From 80260709946304588445e4c67a7357967270fb0c Mon Sep 17 00:00:00 2001 From: John Date: Sun, 27 Apr 2025 20:08:14 +1200 Subject: [PATCH] Working on restore. --- src/main_commands.cpp | 6 +++--- templates/example-nginx/restore.sh | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main_commands.cpp b/src/main_commands.cpp index 05064f6..70533cf 100644 --- a/src/main_commands.cpp +++ b/src/main_commands.cpp @@ -134,19 +134,19 @@ int restore(const std::vector &args) } { // silently uninstalling the current service std::cout << "2) Uninstalling current service..." << std::endl; - env.run_remote_template_command(service_name, "uninstall", {}, true); + env.run_remote_template_command(service_name, "uninstall", {}, false); } { // restore service from backup std::cout << "3) Restoring service from backup..." << std::endl; - env.run_remote_template_command(service_name, "restore", {local_backup_file_path}, true); + env.run_remote_template_command(service_name, "restore", {local_backup_file_path}, false); } // healthcheck the service std::cout << "4) 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", {}, true)) + 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; diff --git a/templates/example-nginx/restore.sh b/templates/example-nginx/restore.sh index f1260fb..bad718d 100644 --- a/templates/example-nginx/restore.sh +++ b/templates/example-nginx/restore.sh @@ -20,21 +20,24 @@ if [ ! -f "$BACKUP_FILE" ]; then fi # # Stop container before backup - _stop_container "$CONTAINER_NAME" + _remove_container "$CONTAINER_NAME" +_is_container_running || die "Couldn't stop existing container" +_is_container_exists || die "Couldn't remove existing container" # Remove existing data folder -echo "Removing existing data folder $LOCAL_DATA_FOLDER..." -rm -rf "$LOCAL_DATA_FOLDER/*" +echo "Deleting ALL data in $LOCAL_DATA_FOLDER." +rm -rf "$LOCAL_DATA_FOLDER" +[ ! -d "$LOCAL_DATA_FOLDER" ] || die "Failed to delete $LOCAL_DATA_FOLDER" + +mkdir -p "$LOCAL_DATA_FOLDER" +[ -d "$LOCAL_DATA_FOLDER" ] || die "Failed to create $LOCAL_DATA_FOLDER" # Restore data folder from backup -echo "Restoring data folder from backup $BACKUP_FILE..." if ! tar xzvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER"; then die "Failed to restore data folder from backup" fi # reinstall service -if ! bash ./install.sh; then - die "Failed to reinstall service" -fi +bash ./install.sh || die "Failed to reinstall service after restore" echo "Restore complete! Service is running again on port $HOST_PORT with restored website."