82 lines
2.2 KiB
Bash
Executable File
82 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $(basename "$0") BACKUP_ID
|
|
|
|
Restore the OpenCloud volume from a backup run identified by BACKUP_ID.
|
|
BACKUP_ID should match the directory name under ./backups (e.g. 2025-11-17_12-30).
|
|
EOF
|
|
}
|
|
|
|
if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then
|
|
usage
|
|
exit 0
|
|
fi
|
|
|
|
if [ $# -ne 1 ]; then
|
|
usage >&2
|
|
exit 1
|
|
fi
|
|
|
|
BACKUP_ID=$1
|
|
ROOT_DIR=$(cd "$(dirname "$0")/../.." && pwd)
|
|
BACKUPS_DIR="$ROOT_DIR/backups/$BACKUP_ID"
|
|
|
|
if [ ! -d "$BACKUPS_DIR" ]; then
|
|
printf 'Backup directory not found: %s\n' "$BACKUPS_DIR" >&2
|
|
exit 1
|
|
fi
|
|
|
|
load_env_file() {
|
|
local file=$1
|
|
if [ -f "$file" ]; then
|
|
# shellcheck disable=SC1090
|
|
set -a
|
|
. "$file"
|
|
set +a
|
|
fi
|
|
}
|
|
|
|
# Load shared/service env if present (not strictly required but keeps behavior consistent)
|
|
load_env_file "$ROOT_DIR/.env"
|
|
|
|
COMPOSE_CMD="docker compose"
|
|
cd "$ROOT_DIR"
|
|
|
|
printf 'Stopping OpenCloud service before restore...\n'
|
|
if ! $COMPOSE_CMD stop opencloud >/dev/null 2>&1; then
|
|
printf 'Warning: could not stop OpenCloud service (it may already be stopped).\n' >&2
|
|
fi
|
|
|
|
DATA_ARCHIVE="opencloud_data_${BACKUP_ID}.tar.gz"
|
|
CONFIG_ARCHIVE="opencloud_config_${BACKUP_ID}.tar.gz"
|
|
DATA_HOST_FILE="$BACKUPS_DIR/$DATA_ARCHIVE"
|
|
CONFIG_HOST_FILE="$BACKUPS_DIR/$CONFIG_ARCHIVE"
|
|
DATA_CONTAINER_PATH="/backups/$BACKUP_ID/$DATA_ARCHIVE"
|
|
CONFIG_CONTAINER_PATH="/backups/$BACKUP_ID/$CONFIG_ARCHIVE"
|
|
|
|
if [ ! -f "$DATA_HOST_FILE" ]; then
|
|
printf 'Archive missing: %s\n' "$DATA_HOST_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "$CONFIG_HOST_FILE" ]; then
|
|
printf 'Archive missing: %s\n' "$CONFIG_HOST_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf 'Restoring opencloud-data from %s\n' "$DATA_HOST_FILE"
|
|
$COMPOSE_CMD run --rm restore restore-volume opencloud-data "$DATA_CONTAINER_PATH"
|
|
|
|
printf 'Restoring opencloud-config from %s\n' "$CONFIG_HOST_FILE"
|
|
$COMPOSE_CMD run --rm restore restore-volume opencloud-config "$CONFIG_CONTAINER_PATH"
|
|
|
|
printf '\nRestore command completed. Restart OpenCloud services when ready.\n'
|
|
|
|
printf 'Starting OpenCloud service...\n'
|
|
if ! $COMPOSE_CMD up -d opencloud; then
|
|
printf 'Warning: failed to start OpenCloud service. Please start it manually.\n' >&2
|
|
fi
|