2025-04-27 20:08:14 +12:00

44 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" "LOCAL_DATA_FOLDER"
# Get backup file path from first argument
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
die "Backup file path 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
_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 "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
if ! tar xzvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER"; then
die "Failed to restore data folder from backup"
fi
# reinstall service
bash ./install.sh || die "Failed to reinstall service after restore"
echo "Restore complete! Service is running again on port $HOST_PORT with restored website."