Add 7zip compression; tweak dump settings

This commit is contained in:
Akkadius
2020-03-10 00:14:28 -05:00
parent fa12b146a3
commit c42d6dcd1b
3 changed files with 22 additions and 9 deletions
+20 -6
View File
@@ -90,14 +90,14 @@ bool DatabaseDumpService::IsTarAvailable()
}
/**
* Windows TODO
* Windows
* @return bool
*/
bool DatabaseDumpService::IsRarAvailable()
bool DatabaseDumpService::Is7ZipAvailable()
{
std::string version_output = execute("winrar --version");
return version_output.find("todo") != std::string::npos;
return version_output.find("7-Zip") != std::string::npos;
}
/**
@@ -105,7 +105,7 @@ bool DatabaseDumpService::IsRarAvailable()
*/
bool DatabaseDumpService::HasCompressionBinary()
{
return IsTarAvailable() || IsRarAvailable();
return IsTarAvailable() || Is7ZipAvailable();
}
/**
@@ -285,7 +285,7 @@ void DatabaseDumpService::Dump()
config->DatabaseUsername
);
std::string options = "--compact --allow-keywords --extended-insert";
std::string options = "--allow-keywords --extended-insert";
if (IsDumpWithNoData()) {
options += " --no-data";
@@ -358,7 +358,7 @@ void DatabaseDumpService::Dump()
std::vector<std::string> tables = SplitString(tables_to_dump, ' ');
for (auto &table : tables) {
std::cout << "DROP TABLE `" << table << "`;" << std::endl;
std::cout << "DROP TABLE IF EXISTS `" << table << "`;" << std::endl;
}
if (tables_to_dump.empty()) {
@@ -393,6 +393,20 @@ void DatabaseDumpService::Dump()
);
LogInfo("Compressed dump created at [{}.tar.gz]", GetDumpFileNameWithPath());
}
else if (Is7ZipAvailable()) {
execute(
fmt::format(
"7z a -t7z {}.zip -C {} {}.sql",
GetDumpFileNameWithPath(),
GetSetDumpPath(),
GetDumpFileNameWithPath()
)
);
LogInfo("Compressed dump created at [{}.zip]", GetDumpFileNameWithPath());
}
else {
LogInfo("Compression requested, but no available compression binary was found");
}
}
else {
LogWarning("Compression requested but binary not found... Skipping...");
+1 -1
View File
@@ -80,7 +80,7 @@ private:
std::string GetContentTablesList();
std::string GetLoginTableList();
bool IsTarAvailable();
bool IsRarAvailable();
bool Is7ZipAvailable();
bool HasCompressionBinary();
std::string GetDumpFileNameWithPath();
std::string GetSetDumpPath();