Working on restore.

This commit is contained in:
John 2025-04-27 20:08:14 +12:00
parent 59561824c7
commit 8026070994
2 changed files with 13 additions and 10 deletions

View File

@ -134,19 +134,19 @@ int restore(const std::vector<std::string> &args)
} }
{ // silently uninstalling the current service { // silently uninstalling the current service
std::cout << "2) Uninstalling current service..." << std::endl; 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 { // restore service from backup
std::cout << "3) Restoring service from backup..." << std::endl; 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 // healthcheck the service
std::cout << "4) Healthchecking service..." << std::endl; std::cout << "4) 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", {}, true)) if (env.run_remote_template_command(service_name, "status", {}, false))
std::cout << green_tick << " Service is healthy." << std::endl; std::cout << green_tick << " Service is healthy." << std::endl;
else else
std::cout << red_cross << " Service is NOT healthy." << std::endl; std::cout << red_cross << " Service is NOT healthy." << std::endl;

View File

@ -20,21 +20,24 @@ if [ ! -f "$BACKUP_FILE" ]; then
fi fi
# # Stop container before backup # # 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 # Remove existing data folder
echo "Removing existing data folder $LOCAL_DATA_FOLDER..." echo "Deleting ALL data in $LOCAL_DATA_FOLDER."
rm -rf "$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 # Restore data folder from backup
echo "Restoring data folder from backup $BACKUP_FILE..."
if ! tar xzvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER"; then if ! tar xzvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER"; then
die "Failed to restore data folder from backup" die "Failed to restore data folder from backup"
fi fi
# reinstall service # reinstall service
if ! bash ./install.sh; then bash ./install.sh || die "Failed to reinstall service after restore"
die "Failed to reinstall service"
fi
echo "Restore complete! Service is running again on port $HOST_PORT with restored website." echo "Restore complete! Service is running again on port $HOST_PORT with restored website."