2025-05-03 16:34:54 +12:00

47 lines
1.3 KiB
Bash

#!/bin/bash
# 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.
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"
fi
TEMP_DIR=$2
if [ -z "$TEMP_DIR" ]; then
die "Temporary directory not provided"
fi
# Check if backup file already exists
if [ ! -f "$BACKUP_FILE" ]; then
die "Backup file $BACKUP_FILE does not exist"
fi
# # 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 on port $HOST_PORT with restored content."