From c42d6dcd1b0833fb8cf6fb57f6facb5b583b2dc7 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Tue, 10 Mar 2020 00:14:28 -0500 Subject: [PATCH] Add 7zip compression; tweak dump settings --- common/database/database_dump_service.cpp | 26 +++++++++++++++++------ common/database/database_dump_service.h | 2 +- utils/sql/peq-dump/peq-dump.sh | 3 +-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/common/database/database_dump_service.cpp b/common/database/database_dump_service.cpp index 5d6da79e9..e98a8d830 100644 --- a/common/database/database_dump_service.cpp +++ b/common/database/database_dump_service.cpp @@ -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 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..."); diff --git a/common/database/database_dump_service.h b/common/database/database_dump_service.h index 439a380ba..f0614e85b 100644 --- a/common/database/database_dump_service.h +++ b/common/database/database_dump_service.h @@ -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(); diff --git a/utils/sql/peq-dump/peq-dump.sh b/utils/sql/peq-dump/peq-dump.sh index 7fd9bf278..911439c8f 100755 --- a/utils/sql/peq-dump/peq-dump.sh +++ b/utils/sql/peq-dump/peq-dump.sh @@ -52,7 +52,6 @@ bash -c "${world_bin} database:dump --system-tables --dump-output-to-console > $ ############################################# # "all" exports ############################################# - 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" @@ -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:]') 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..." rm -rf ${dump_path}