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

View File

@ -90,14 +90,14 @@ bool DatabaseDumpService::IsTarAvailable()
} }
/** /**
* Windows TODO * Windows
* @return bool * @return bool
*/ */
bool DatabaseDumpService::IsRarAvailable() bool DatabaseDumpService::Is7ZipAvailable()
{ {
std::string version_output = execute("winrar --version"); 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() bool DatabaseDumpService::HasCompressionBinary()
{ {
return IsTarAvailable() || IsRarAvailable(); return IsTarAvailable() || Is7ZipAvailable();
} }
/** /**
@ -285,7 +285,7 @@ void DatabaseDumpService::Dump()
config->DatabaseUsername config->DatabaseUsername
); );
std::string options = "--compact --allow-keywords --extended-insert"; std::string options = "--allow-keywords --extended-insert";
if (IsDumpWithNoData()) { if (IsDumpWithNoData()) {
options += " --no-data"; options += " --no-data";
@ -358,7 +358,7 @@ void DatabaseDumpService::Dump()
std::vector<std::string> tables = SplitString(tables_to_dump, ' '); std::vector<std::string> tables = SplitString(tables_to_dump, ' ');
for (auto &table : tables) { 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()) { if (tables_to_dump.empty()) {
@ -393,6 +393,20 @@ void DatabaseDumpService::Dump()
); );
LogInfo("Compressed dump created at [{}.tar.gz]", GetDumpFileNameWithPath()); 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 { else {
LogWarning("Compression requested but binary not found... Skipping..."); LogWarning("Compression requested but binary not found... Skipping...");

View File

@ -80,7 +80,7 @@ private:
std::string GetContentTablesList(); std::string GetContentTablesList();
std::string GetLoginTableList(); std::string GetLoginTableList();
bool IsTarAvailable(); bool IsTarAvailable();
bool IsRarAvailable(); bool Is7ZipAvailable();
bool HasCompressionBinary(); bool HasCompressionBinary();
std::string GetDumpFileNameWithPath(); std::string GetDumpFileNameWithPath();
std::string GetSetDumpPath(); std::string GetSetDumpPath();

View File

@ -52,7 +52,6 @@ bash -c "${world_bin} database:dump --system-tables --dump-output-to-console > $
############################################# #############################################
# "all" exports # "all" exports
############################################# #############################################
bash -c "cd ${dump_path} && ls * | grep create | sed 's/.*/source &;/' > create_all_tables.sql" bash -c "cd ${dump_path} && ls * | grep create | sed 's/.*/source &;/' > create_all_tables.sql"
bash -c "cd ${dump_path} && ls * | grep drop | sed 's/.*/source &;/' > drop_all_tables.sql" bash -c "cd ${dump_path} && ls * | grep drop | sed 's/.*/source &;/' > drop_all_tables.sql"
@ -62,7 +61,7 @@ bash -c "cd ${dump_path} && ls * | grep drop | sed 's/.*/source &;/' > drop_all_
human_date=$(date +"%B-%d-%Y" | tr '[:upper:]' '[:lower:]') human_date=$(date +"%B-%d-%Y" | tr '[:upper:]' '[:lower:]')
echo "Compressing..." echo "Compressing..."
bash -c "cd ${dump_path} && zip peq-latest.zip * && mv ${dump_path}peq-latest.zip /tmp/peq-latest.zip" bash -c "cd /tmp/ && rm peq-latest.zip && zip peq-latest.zip peq-dump/* && mv ${dump_path}peq-latest.zip /tmp/peq-latest.zip"
echo "Cleaning up..." echo "Cleaning up..."
rm -rf ${dump_path} rm -rf ${dump_path}