Working on restore

This commit is contained in:
John 2025-04-27 19:49:18 +12:00
parent 214049519c
commit c1b9b2a152
4 changed files with 27 additions and 15 deletions

View File

@ -127,6 +127,15 @@ int restore(const std::vector<std::string> &args)
} }
std::cout << "Backup complete." << std::endl; std::cout << "Backup complete." << std::endl;
} }
{ // uninstalling the current service
std::cout << "2) Uninstalling current service..." << std::endl;
if (!uninstall(uninstall_args,true)) // silent=true
{
std::cerr << std::endl;
std::cerr << "Error: Uninstall failed, restore aborted." << std::endl;
return 1;
}
}
{ // 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;
@ -202,7 +211,7 @@ int backup(const std::vector<std::string> & args, bool silent) {
// Create backups directory on server if it doesn't exist // Create backups directory on server if it doesn't exist
std::string remote_backups_dir = get_remote_backups_path(server_name); std::string remote_backups_dir = get_remote_backups_path(server_name);
if (!silent) std::cout << "Remote backups directory on "<< server_name <<": " << remote_backups_dir << std::endl; if (!silent) std::cout << "Remote backups directory on "<< server_name <<": " << remote_backups_dir << std::endl;
std::string mkdir_cmd = "'mkdir -p " + quote(remote_backups_dir) + "'"; std::string mkdir_cmd = "mkdir -p " + quote(remote_backups_dir);
if (!env.execute_ssh_command(mkdir_cmd)) { if (!env.execute_ssh_command(mkdir_cmd)) {
std::cerr << "Failed to create backups directory on server" << std::endl; std::cerr << "Failed to create backups directory on server" << std::endl;
return false; return false;

View File

@ -84,7 +84,7 @@ std::string server_env::construct_standard_command_run_cmd(const std::string &se
argstr += " " + quote(dequote(trim(arg))); argstr += " " + quote(dequote(trim(arg)));
} }
sCommand scommand(remote_service_template_path, "bash " + quote(script_path) + " " + argstr + (silent ? " > /dev/null 2>&1" : ""), env_vars); sCommand scommand(remote_service_template_path, "bash " + quote(script_path) + argstr + (silent ? " > /dev/null 2>&1" : ""), env_vars);
std::string run_cmd = scommand.construct_safecmd(); std::string run_cmd = scommand.construct_safecmd();
return run_cmd; return run_cmd;
} }

View File

@ -33,9 +33,9 @@ _check_docker_installed || die "Docker test failed, aborting installation..."
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG"
# remove and restart, as the env may have changed. # remove and restart, as the env may have changed.
bash ./stop.sh $1 || die "Failed to stop container ${CONTAINER_NAME}" bash ./stop.sh || die "Failed to stop container ${CONTAINER_NAME}"
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}" _remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
bash ./start.sh $1 || die "Failed to start container ${CONTAINER_NAME}" bash ./start.sh || die "Failed to start container ${CONTAINER_NAME}"
echo "Installation of ${CONTAINER_NAME} complete" echo "Installation of ${CONTAINER_NAME} complete"
echo "You can access the service at http://${SERVER}:${HOST_PORT}" echo "You can access the service at http://${SERVER}:${HOST_PORT}"

View File

@ -20,18 +20,21 @@ if [ ! -f "$BACKUP_FILE" ]; then
fi fi
# # Stop container before backup # # Stop container before backup
# _stop_container "$CONTAINER_NAME" _stop_container "$CONTAINER_NAME"
# Create backup of data folder # Remove existing data folder
# echo "Creating backup of $LOCAL_DATA_FOLDER..." echo "Removing existing data folder $LOCAL_DATA_FOLDER..."
# if ! tar zcvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" .; then rm -rf "$LOCAL_DATA_FOLDER/*"
# _start_container "$CONTAINER_NAME"
# die "Failed to create backup"
# fi
# # Start container after backup # Restore data folder from backup
# _start_container "$CONTAINER_NAME" 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
# echo "Backup created successfully: $BACKUP_FILE" # reinstall service
if ! bash ./install.sh; then
die "Failed to reinstall service"
fi
echo "Backup restored successfully!" echo "Restore complete! Service is running again on port $HOST_PORT with restored website."