#!/bin/bash
source "${AGENT_PATH}/_common.sh" || _die "Failed to source _common.sh"
_check_required_env_vars

# Simple Object Storage Restore Script
# Restores data from a backup file.



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

echo "Restore complete. Reinstalling service..."

bash ./install.sh || _die "Failed to reinstall service after restore"

echo "Service ${CONTAINER_NAME} restored and reinstalled."
