Squashkiwi backup and restore fully working.
This commit is contained in:
parent
5bc7a05a46
commit
5e8189c103
@ -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) {
|
||||
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
|
||||
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
|
||||
std::cout << "3) Healthchecking service..." << std::endl;
|
||||
std::string green_tick = "\033[32m✓\033[0m";
|
||||
std::string red_cross = "\033[31m✗\033[0m";
|
||||
if (env.run_remote_template_command(service_name, "status", {}, false))
|
||||
std::cout << green_tick << " Service is healthy." << std::endl;
|
||||
else
|
||||
std::cout << red_cross << " Service is NOT healthy." << std::endl;
|
||||
bool healthy= (env.run_remote_template_command(service_name, "status", {}, silent));
|
||||
if (!silent)
|
||||
std::cout << (healthy ? green_tick : red_cross) << " Service is " << (healthy ? "healthy" : "NOT healthy") << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace dropshell {
|
||||
namespace main_commands {
|
||||
|
||||
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);
|
||||
} // namespace main_commands
|
||||
|
||||
|
@ -66,7 +66,7 @@ bool service_runner::install() {
|
||||
|
||||
// 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() + "' " +
|
||||
quote(tinfo.local_template_path + "/") + " "+
|
||||
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;
|
||||
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() + "' " +
|
||||
quote(local_service_path + "/") + " "+
|
||||
m_server_env.get_SSH_USER() + "@" + m_server_env.get_SSH_HOST() + ":" +
|
||||
|
@ -31,7 +31,7 @@ mkdir -p "$LOCAL_DATA_FOLDER"
|
||||
|
||||
# Restore data folder from backup
|
||||
# --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"
|
||||
fi
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user