#!/bin/bash # Restore a backup produced by scripts/backup.sh. # Usage: scripts/restore.sh [--yes] set -euo pipefail cd "$(dirname "$0")/.." set -a; [ -f .env.production ] && . ./.env.production; set +a FILE="$1"; PASS_FILE="${BACKUP_PASSPHRASE_FILE:-$HOME/.config/chat-spboucher-ai/backup.pass}" [ "${2:-}" = "--yes" ] || { echo "Cette opération REMPLACE la base $DATABASE_URL et le dossier uploads. Relance avec --yes pour confirmer."; exit 1; } export PATH="/opt/homebrew/opt/postgresql@17/bin:/opt/homebrew/bin:$PATH" TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT openssl enc -d -aes-256-cbc -pbkdf2 -iter 200000 -pass "file:$PASS_FILE" -in "$FILE" | tar -C "$TMP" -xf - pm2 stop chat-spboucher-ai >/dev/null 2>&1 || true pg_restore --clean --if-exists --no-owner -d "$DATABASE_URL" "$TMP/db.dump" mkdir -p "${DATA_DIR:-./data}"; tar -C "${DATA_DIR:-./data}" -xzf "$TMP/uploads.tgz" pm2 start chat-spboucher-ai >/dev/null 2>&1 || true echo "restore ok"