Repository Public
1#!/bin/bash2# Restores an encrypted backup into a database (which must exist and be empty).3# scripts/restore.sh <backup.dump.enc> <postgres URL of the target database>4set -euo pipefail5cd "$(dirname "$0")/.."6# Read only the variables this script needs from .env (the file is not shell syntax: values may contain spaces).7if [ -f .env ]; then8 while IFS='=' read -r k v; do9 case "$k" in DATABASE_URL|BACKUP_DIR|BACKUP_PASSPHRASE_FILE)10 v="${v%\"}"; v="${v#\"}"; [ -n "${!k:-}" ] || export "$k=$v" ;;11 esac12 done < .env13fi14file="${1:?backup file}"; target="${2:?target database URL}"15: "${BACKUP_PASSPHRASE_FILE:?BACKUP_PASSPHRASE_FILE missing}"16export PATH="/opt/homebrew/opt/postgresql@17/bin:/opt/homebrew/bin:$PATH"17openssl enc -d -aes-256-cbc -pbkdf2 -iter 200000 -pass "file:$BACKUP_PASSPHRASE_FILE" -in "$file" | pg_restore --no-owner --no-privileges --exit-on-error -d "$target"18echo "restored $file"19