mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-13 10:52:28 +00:00
[Backups] Move world database:dump to use MySQL credentials file (#3410)
This commit is contained in:
parent
1e22baf267
commit
53563b9720
@ -93,6 +93,8 @@ std::string DatabaseDumpService::GetMySQLVersion()
|
|||||||
return Strings::Trim(version_output);
|
return Strings::Trim(version_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string CREDENTIALS_FILE = "login.my.cnf";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -101,21 +103,15 @@ std::string DatabaseDumpService::GetBaseMySQLDumpCommand()
|
|||||||
auto config = EQEmuConfig::get();
|
auto config = EQEmuConfig::get();
|
||||||
if (IsDumpContentTables() && !config->ContentDbHost.empty()) {
|
if (IsDumpContentTables() && !config->ContentDbHost.empty()) {
|
||||||
return fmt::format(
|
return fmt::format(
|
||||||
"mysqldump -u {} -p{} -h {} --port={} {}",
|
"mysqldump --defaults-extra-file={} {}",
|
||||||
config->ContentDbUsername,
|
CREDENTIALS_FILE,
|
||||||
config->ContentDbPassword,
|
|
||||||
config->ContentDbHost,
|
|
||||||
config->ContentDbPort,
|
|
||||||
config->ContentDbName
|
config->ContentDbName
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return fmt::format(
|
return fmt::format(
|
||||||
"mysqldump -u {} -p{} -h {} --port={} {}",
|
"mysqldump --defaults-extra-file={} {}",
|
||||||
config->DatabaseUsername,
|
CREDENTIALS_FILE,
|
||||||
config->DatabasePassword,
|
|
||||||
config->DatabaseHost,
|
|
||||||
config->DatabasePort,
|
|
||||||
config->DatabaseDB
|
config->DatabaseDB
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -321,6 +317,7 @@ void DatabaseDumpService::DatabaseDump()
|
|||||||
pipe_file
|
pipe_file
|
||||||
);
|
);
|
||||||
|
|
||||||
|
BuildCredentialsFile();
|
||||||
std::string execution_result = Process::execute(execute_command);
|
std::string execution_result = Process::execute(execute_command);
|
||||||
if (!execution_result.empty() && IsDumpOutputToConsole()) {
|
if (!execution_result.empty() && IsDumpOutputToConsole()) {
|
||||||
std::cout << execution_result;
|
std::cout << execution_result;
|
||||||
@ -352,7 +349,6 @@ void DatabaseDumpService::DatabaseDump()
|
|||||||
}
|
}
|
||||||
|
|
||||||
LogInfo("Database dump created at [{}.sql]", GetDumpFileNameWithPath());
|
LogInfo("Database dump created at [{}.sql]", GetDumpFileNameWithPath());
|
||||||
|
|
||||||
if (IsDumpWithCompression() && !IsDumpOutputToConsole()) {
|
if (IsDumpWithCompression() && !IsDumpOutputToConsole()) {
|
||||||
if (HasCompressionBinary()) {
|
if (HasCompressionBinary()) {
|
||||||
LogInfo("Compression requested. Compressing dump [{}.sql]", GetDumpFileNameWithPath());
|
LogInfo("Compression requested. Compressing dump [{}.sql]", GetDumpFileNameWithPath());
|
||||||
@ -389,6 +385,8 @@ void DatabaseDumpService::DatabaseDump()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RemoveCredentialsFile();
|
||||||
|
|
||||||
// LogDebug("[{}] dump-to-console", IsDumpOutputToConsole());
|
// LogDebug("[{}] dump-to-console", IsDumpOutputToConsole());
|
||||||
// LogDebug("[{}] dump-path", GetSetDumpPath());
|
// LogDebug("[{}] dump-path", GetSetDumpPath());
|
||||||
// LogDebug("[{}] compression", (IsDumpWithCompression() ? "true" : "false"));
|
// LogDebug("[{}] compression", (IsDumpWithCompression() ? "true" : "false"));
|
||||||
@ -568,4 +566,41 @@ void DatabaseDumpService::RemoveSqlBackup()
|
|||||||
if (File::Exists(file)) {
|
if (File::Exists(file)) {
|
||||||
std::filesystem::remove(file);
|
std::filesystem::remove(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RemoveCredentialsFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DatabaseDumpService::BuildCredentialsFile()
|
||||||
|
{
|
||||||
|
auto config = EQEmuConfig::get();
|
||||||
|
std::ofstream out(CREDENTIALS_FILE);
|
||||||
|
if (out.is_open()) {
|
||||||
|
if (IsDumpContentTables() && !config->ContentDbHost.empty()) {
|
||||||
|
out << "[mysqldump]" << std::endl;
|
||||||
|
out << "user=" << config->ContentDbUsername << std::endl;
|
||||||
|
out << "password=" << config->ContentDbPassword << std::endl;
|
||||||
|
out << "host=" << config->ContentDbHost << std::endl;
|
||||||
|
out << "port=" << config->ContentDbPort << std::endl;
|
||||||
|
out << "default-character-set=utf8" << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
out << "[mysqldump]" << std::endl;
|
||||||
|
out << "user=" << config->DatabaseUsername << std::endl;
|
||||||
|
out << "password=" << config->DatabasePassword << std::endl;
|
||||||
|
out << "host=" << config->DatabaseHost << std::endl;
|
||||||
|
out << "port=" << config->DatabasePort << std::endl;
|
||||||
|
out << "default-character-set=utf8" << std::endl;
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogError("Failed to open credentials file for writing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DatabaseDumpService::RemoveCredentialsFile()
|
||||||
|
{
|
||||||
|
if (File::Exists(CREDENTIALS_FILE)) {
|
||||||
|
std::filesystem::remove(CREDENTIALS_FILE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,6 +93,8 @@ private:
|
|||||||
std::string GetSetDumpPath();
|
std::string GetSetDumpPath();
|
||||||
std::string GetQueryServTables();
|
std::string GetQueryServTables();
|
||||||
void RemoveSqlBackup();
|
void RemoveSqlBackup();
|
||||||
|
void BuildCredentialsFile();
|
||||||
|
void RemoveCredentialsFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user