#!/bin/bash # Immich Restore Script # This script restores an Immich installation from backups created by backup-immich.sh # Based on recommendations from https://immich.app/docs/administration/backup-and-restore/ # Set up error handling set -e # Load environment variables from the .env file ENV_FILE="$(dirname "$0")/../.env" if [ -f "$ENV_FILE" ]; then echo "Loading environment variables from $ENV_FILE" source "$ENV_FILE" else echo "Error: .env file not found in $(dirname "$0")/.." exit 1 fi # Set up logging to central logs directory LOG_DIR="$(dirname "$0")/../logs" mkdir -p "$LOG_DIR" LOG_FILE="${LOG_DIR}/immich-restore.log" # Function to log with timestamp log_message() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE" } # Function to display usage usage() { echo "Usage: $0 --db-backup --uploads-backup [options]" echo "" echo "Required arguments:" echo " --db-backup PATH Path to database backup file (.sql.gz)" echo " --uploads-backup PATH Path to uploads backup file (.tar.gz)" echo "" echo "Optional arguments:" echo " --dry-run Show what would be restored without making changes" echo " --skip-db Skip database restoration" echo " --skip-uploads Skip uploads restoration" echo " --help Show this help message" echo "" echo "Example:" echo " $0 --db-backup ./immich_backups/immich_db_backup_20250526_120000.sql.gz \\" echo " --uploads-backup ./immich_backups/immich_uploads_20250526_120000.tar.gz" } # Parse command line arguments DB_BACKUP="" UPLOADS_BACKUP="" DRY_RUN=false SKIP_DB=false SKIP_UPLOADS=false while [[ $# -gt 0 ]]; do case $1 in --db-backup) DB_BACKUP="$2" shift 2 ;; --uploads-backup) UPLOADS_BACKUP="$2" shift 2 ;; --dry-run) DRY_RUN=true shift ;; --skip-db) SKIP_DB=true shift ;; --skip-uploads) SKIP_UPLOADS=true shift ;; --help) usage exit 0 ;; *) echo "Unknown option: $1" usage exit 1 ;; esac done # Validate required arguments if [ -z "$DB_BACKUP" ] && [ "$SKIP_DB" = false ]; then echo "Error: --db-backup is required unless --skip-db is specified" usage exit 1 fi if [ -z "$UPLOADS_BACKUP" ] && [ "$SKIP_UPLOADS" = false ]; then echo "Error: --uploads-backup is required unless --skip-uploads is specified" usage exit 1 fi # Validate backup files exist if [ "$SKIP_DB" = false ] && [ ! -f "$DB_BACKUP" ]; then echo "Error: Database backup file not found: $DB_BACKUP" exit 1 fi if [ "$SKIP_UPLOADS" = false ] && [ ! -f "$UPLOADS_BACKUP" ]; then echo "Error: Uploads backup file not found: $UPLOADS_BACKUP" exit 1 fi echo "=== IMMICH RESTORE OPERATION ===" echo "Database backup: ${DB_BACKUP:-SKIPPED}" echo "Uploads backup: ${UPLOADS_BACKUP:-SKIPPED}" echo "Dry run mode: $DRY_RUN" echo "" if [ "$DRY_RUN" = true ]; then echo "DRY RUN MODE - No changes will be made" echo "" fi # TODO: Implement restore logic echo "⚠️ RESTORE SCRIPT TEMPLATE ⚠️" echo "" echo "This is a template script. Implementation needed:" echo "" echo "1. Stop Immich containers" echo "2. Restore database (if not skipped):" echo " - Decompress $DB_BACKUP" echo " - Execute SQL restore commands" echo "3. Restore uploads (if not skipped):" echo " - Extract $UPLOADS_BACKUP to $UPLOAD_LOCATION" echo " - Set proper ownership and permissions" echo "4. Restart Immich containers" echo "5. Verify restoration" echo "" echo "For detailed restore instructions, see:" echo "https://immich.app/docs/administration/backup-and-restore/"