diff --git a/src/main_commands.cpp b/src/main_commands.cpp index 10c77b4..2f6e588 100644 --- a/src/main_commands.cpp +++ b/src/main_commands.cpp @@ -54,7 +54,7 @@ int init(const std::vector &args) } } -int restore(const std::vector &args) +int restore(const std::vector &args, bool silent) { if (args.size() < 4) { std::cerr << "Error: not enough arguments. dropshell restore " << std::endl; @@ -135,17 +135,25 @@ int restore(const std::vector &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; } diff --git a/src/main_commands.hpp b/src/main_commands.hpp index b0830ee..ddf10df 100644 --- a/src/main_commands.hpp +++ b/src/main_commands.hpp @@ -9,7 +9,7 @@ namespace dropshell { namespace main_commands { int init(const std::vector &args); - int restore(const std::vector &args); + int restore(const std::vector &args, bool silent=false); int backup(const std::vector &args, bool silent=false); } // namespace main_commands diff --git a/src/service_runner.cpp b/src/service_runner.cpp index 4b0ddcb..382959d 100644 --- a/src/service_runner.cpp +++ b/src/service_runner.cpp @@ -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 <