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