biiig wrench

This commit is contained in:
Your Name
2025-05-03 22:58:39 +12:00
parent 107034cf7b
commit 340170b248
51 changed files with 347 additions and 395 deletions

View File

@ -1,46 +1,23 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh" || _die "Failed to source _common.sh"
# RESTORE SCRIPT
# The restore script is OPTIONAL.
# It is used to restore the service on the server from a backup file.
# It is called with one argument: the path to the backup file.
# Simple Object Storage Restore Script
# Restores data from a backup file.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
# Get backup file path from first argument
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
die "Backup file path not provided"
_check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
echo "Uninstalling service before restore..."
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
echo "Restoring data for ${CONTAINER_NAME} from ${BACKUP_FILE}..."
if ! autorestore "volume=${VOLUME_NAME}" "$1" "$2"; then
_die "Failed to restore data from backup file"
fi
TEMP_DIR=$2
if [ -z "$TEMP_DIR" ]; then
die "Temporary directory not provided"
fi
echo "Restore complete. Reinstalling service..."
# Check if backup file already exists
if [ ! -f "$BACKUP_FILE" ]; then
die "Backup file $BACKUP_FILE does not exist"
fi
bash ./install.sh || _die "Failed to reinstall service after restore"
# # Stop container before backup
bash ./uninstall.sh || die "Failed to uninstall service before restore"
# Remove existing data folder
echo "Deleting ALL data in $VOLUME_NAME."
docker run --rm -v ${VOLUME_NAME}:/data alpine sh -c "\
rm -rf /data/*"
echo "Restoring data from $BACKUP_FILE to $VOLUME_NAME."
docker run --rm \
-v ${VOLUME_NAME}:/data \
-v ${BACKUP_FILE}:/backup.tar.gz \
alpine sh -c "\
tar xzvf /backup.tar.gz -C /data --strip-components=1"
# reinstall service - ensure everything is latest.
bash ./install.sh || die "Failed to reinstall service after restore"
echo "Restore complete! Service is running again."
echo "Service ${CONTAINER_NAME} restored and reinstalled."