Squashkiwi backup and restore fully working.

This commit is contained in:
John 2025-04-27 21:13:38 +12:00
parent 5bc7a05a46
commit 5e8189c103
4 changed files with 18 additions and 10 deletions

View File

@ -54,7 +54,7 @@ int init(const std::vector<std::string> &args)
} }
} }
int restore(const std::vector<std::string> &args) int restore(const std::vector<std::string> &args, bool silent)
{ {
if (args.size() < 4) { if (args.size() < 4) {
std::cerr << "Error: not enough arguments. dropshell restore <server> <service> <backup-file>" << std::endl; std::cerr << "Error: not enough arguments. dropshell restore <server> <service> <backup-file>" << std::endl;
@ -135,17 +135,25 @@ int restore(const std::vector<std::string> &args)
{ // restore service from backup { // restore service from backup
std::cout << "2) Restoring service from backup..." << std::endl; std::cout << "2) Restoring service from backup..." << std::endl;
env.run_remote_template_command(service_name, "restore", {local_backup_file_path}, false); std::string remote_backups_dir = get_remote_backups_path(server_name);
std::string remote_backup_file_path = remote_backups_dir + "/" + backup_file;
// Copy backup file from local to server
std::string scp_cmd = "scp -P " + env.get_SSH_PORT() + " " + quote(local_backup_file_path) + " " + env.get_SSH_USER() + "@" + env.get_SSH_HOST() + ":" + quote(remote_backup_file_path) + (silent ? " > /dev/null 2>&1" : "");
if (!env.execute_local_command(scp_cmd)) {
std::cerr << "Failed to copy backup file from server" << std::endl;
return false;
}
env.run_remote_template_command(service_name, "restore", {remote_backup_file_path}, silent);
} }
// healthcheck the service // healthcheck the service
std::cout << "3) Healthchecking service..." << std::endl; std::cout << "3) Healthchecking service..." << std::endl;
std::string green_tick = "\033[32m✓\033[0m"; std::string green_tick = "\033[32m✓\033[0m";
std::string red_cross = "\033[31m✗\033[0m"; std::string red_cross = "\033[31m✗\033[0m";
if (env.run_remote_template_command(service_name, "status", {}, false)) bool healthy= (env.run_remote_template_command(service_name, "status", {}, silent));
std::cout << green_tick << " Service is healthy." << std::endl; if (!silent)
else std::cout << (healthy ? green_tick : red_cross) << " Service is " << (healthy ? "healthy" : "NOT healthy") << std::endl;
std::cout << red_cross << " Service is NOT healthy." << std::endl;
return 0; return 0;
} }

View File

@ -9,7 +9,7 @@ namespace dropshell {
namespace main_commands { namespace main_commands {
int init(const std::vector<std::string> &args); int init(const std::vector<std::string> &args);
int restore(const std::vector<std::string> &args); int restore(const std::vector<std::string> &args, bool silent=false);
int backup(const std::vector<std::string> &args, bool silent=false); int backup(const std::vector<std::string> &args, bool silent=false);
} // namespace main_commands } // namespace main_commands

View File

@ -66,7 +66,7 @@ bool service_runner::install() {
// Copy template files // Copy template files
{ {
std::cout << "Copying template files from [LOCAL] " << tinfo.local_template_path << std::endl << std::string(24,' ')<<"to [REMOTE] " << mRemote_service_template_path << "/" << std::endl; std::cout << "Copying: [LOCAL] " << tinfo.local_template_path << std::endl << std::string(8,' ')<<"[REMOTE] " << mRemote_service_template_path << "/" << std::endl;
std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + m_server_env.get_SSH_PORT() + "' " + std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + m_server_env.get_SSH_PORT() + "' " +
quote(tinfo.local_template_path + "/") + " "+ quote(tinfo.local_template_path + "/") + " "+
m_server_env.get_SSH_USER() + "@" + m_server_env.get_SSH_HOST() + ":" + m_server_env.get_SSH_USER() + "@" + m_server_env.get_SSH_HOST() + ":" +
@ -87,7 +87,7 @@ bool service_runner::install() {
std::cerr << "Error: Service directory not found: " << local_service_path << std::endl; std::cerr << "Error: Service directory not found: " << local_service_path << std::endl;
return false; return false;
} }
std::cout << "Copying service files from [LOCAL] " << local_service_path << std::endl <<std::string(24,' ')<<"to [REMOTE] " << mRemote_service_config_path << std::endl; std::cout << "Copying: [LOCAL] " << local_service_path << std::endl <<std::string(8,' ')<<"[REMOTE] " << mRemote_service_config_path << std::endl;
std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + m_server_env.get_SSH_PORT() + "' " + std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + m_server_env.get_SSH_PORT() + "' " +
quote(local_service_path + "/") + " "+ quote(local_service_path + "/") + " "+
m_server_env.get_SSH_USER() + "@" + m_server_env.get_SSH_HOST() + ":" + m_server_env.get_SSH_USER() + "@" + m_server_env.get_SSH_HOST() + ":" +

View File

@ -31,7 +31,7 @@ mkdir -p "$LOCAL_DATA_FOLDER"
# Restore data folder from backup # Restore data folder from backup
# --strip-components=1 removes the parent folder in the tgz from the restore paths. # --strip-components=1 removes the parent folder in the tgz from the restore paths.
if ! tar xzvf --strip-components=1 "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER"; then if ! tar xzvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" --strip-components=1; then
die "Failed to restore data folder from backup" die "Failed to restore data folder from backup"
fi fi