Recovery
This procedure restores Nyravio from a backup created with the Backup procedure. It includes comprehensive preflight verification before making any destructive changes.
Prerequisites
Section titled “Prerequisites”- The complete backup directory with all four files (
backup.sql,backup-metadata.json,env.backup,uploads.tar) - The original
NYRAVIO_ADMIN_ENCRYPTION_KEYin the backup’senv.backup - The exact Docker image recorded in backup metadata (available locally)
- Required tools:
docker,jq,curl,sha256sum
Compatibility requirements
Section titled “Compatibility requirements”The restore procedure supports restoring into a compatible Nyravio deployment:
- Same Compose project
- Same PostgreSQL major version
- Same database credentials
- Matching resolved volume identities
Cross-version PostgreSQL restores, restores with changed database passwords, mismatched volume configurations, or restores into unrelated deployments are not supported.
Atomicity boundaries
Section titled “Atomicity boundaries”| Component | Atomicity |
|---|---|
| Database restore | Atomic — --single-transaction rolls back the entire operation on any failure |
| Uploads restore | Not atomic — if extraction fails, re-run from the uploads step before starting the application |
Restore procedure
Section titled “Restore procedure”The procedure has two phases: preflight verification (read-only, no changes) and destructive operations (only after all preflight passes).
Full restore script
Section titled “Full restore script”set -euo pipefail
# ── Point BACKUP_DIR at your backup ──BACKUP_DIR="/path/to/nyravio-backup-XXXXXXXXXX"
# ── Preflight: all verification completes before any changes ──
# Required toolsfor cmd in docker jq curl sha256sum; do command -v "$cmd" > /dev/null 2>&1 || { echo "Error: $cmd not found"; exit 1; }done
# Pin the supported Compose fileCOMPOSE_YAML="$(pwd)/compose.yaml"[ -f "$COMPOSE_YAML" ] || { echo "Error: compose.yaml not found in $(pwd)"; exit 1}
# Reject shell overrides[ -z "${COMPOSE_FILE:-}" ] || { echo "Error: COMPOSE_FILE is set — unset it"; exit 1}[ -z "${COMPOSE_ENV_FILES:-}" ] || { echo "Error: COMPOSE_ENV_FILES is set — unset it"; exit 1}[ -z "${COMPOSE_PROJECT_NAME:-}" ] || { echo "Error: COMPOSE_PROJECT_NAME is set — unset it"; exit 1}
# Verify backup artifacts existfor f in backup.sql backup-metadata.json env.backup uploads.tar; do [ -f "$BACKUP_DIR/$f" ] || { echo "Error: missing: $BACKUP_DIR/$f"; exit 1; }done
# Secure temporary files (cleaned up on exit)CFG_CURRENT=$(mktemp) CFG_RESTORE=$(mktemp) CRED_TMP=$(mktemp)chmod 600 "$CFG_CURRENT" "$CFG_RESTORE" "$CRED_TMP"trap 'rm -f "$CFG_CURRENT" "$CFG_RESTORE" "$CRED_TMP"' EXIT
# Verify checksumsEXPECTED=$(jq -re '.dump_sha256' "$BACKUP_DIR/backup-metadata.json")ACTUAL=$(sha256sum "$BACKUP_DIR/backup.sql" | awk '{print $1}')[ "$ACTUAL" = "$EXPECTED" ] || { echo "Error: backup.sql checksum mismatch"; exit 1}
EXPECTED=$(jq -re '.uploads_sha256' "$BACKUP_DIR/backup-metadata.json")ACTUAL=$(sha256sum "$BACKUP_DIR/uploads.tar" | awk '{print $1}')[ "$ACTUAL" = "$EXPECTED" ] || { echo "Error: uploads.tar checksum mismatch"; exit 1}
EXPECTED=$(jq -re '.env_sha256' "$BACKUP_DIR/backup-metadata.json")ACTUAL=$(sha256sum "$BACKUP_DIR/env.backup" | awk '{print $1}')[ "$ACTUAL" = "$EXPECTED" ] || { echo "Error: env.backup checksum mismatch"; exit 1}
# Verify application image identitySTORED_IMAGE_ID=$(jq -re '.image_id' "$BACKUP_DIR/backup-metadata.json")STORED_IMAGE=$(jq -re '.nyravio_image' "$BACKUP_DIR/backup-metadata.json")RESTORE_IMAGE="${NYRAVIO_IMAGE:-$STORED_IMAGE}"ACTUAL_IMAGE_ID=$(docker image inspect --format='{{.Id}}' "$RESTORE_IMAGE" 2>/dev/null) || { echo "Error: image not found locally: $RESTORE_IMAGE"; exit 1}[ "$ACTUAL_IMAGE_ID" = "$STORED_IMAGE_ID" ] || { echo "Error: image ID mismatch for $RESTORE_IMAGE" echo " Expected: $STORED_IMAGE_ID" echo " Actual: $ACTUAL_IMAGE_ID"; exit 1}export NYRAVIO_IMAGE="$RESTORE_IMAGE"
# Verify Compose configuration compatibilitydocker compose --file "$COMPOSE_YAML" config --format json > "$CFG_CURRENT" 2>/dev/nulldocker compose --file "$COMPOSE_YAML" --env-file "$BACKUP_DIR/env.backup" \ config --format json > "$CFG_RESTORE" 2>/dev/null
COMPOSE_PROJECT=$(jq -re '.name' "$CFG_CURRENT")DC=(docker compose --file "$COMPOSE_YAML" --project-name "$COMPOSE_PROJECT" \ --project-directory "$(pwd)")
# Verify project identity, database settings, volume identitiesRESTORE_PROJECT=$(jq -re '.name' "$CFG_RESTORE")[ "$COMPOSE_PROJECT" = "$RESTORE_PROJECT" ] || { echo "Error: Compose project mismatch"; exit 1}
# Verify database user and name matchCURRENT_DB_USER=$(jq -re '.services.db.environment.POSTGRES_USER' "$CFG_CURRENT")RESTORE_DB_USER=$(jq -re '.services.db.environment.POSTGRES_USER' "$CFG_RESTORE")[ "$CURRENT_DB_USER" = "$RESTORE_DB_USER" ] || { echo "Error: database user mismatch"; exit 1}
# Verify PostgreSQL major versionDB_CONTAINER=$("${DC[@]}" ps -q db)STORED_PG=$(jq -re '.pg_version' "$BACKUP_DIR/backup-metadata.json")CURRENT_PG=$(docker exec "$DB_CONTAINER" psql -X -U "$CURRENT_DB_USER" \ -d "$(jq -re '.services.db.environment.POSTGRES_DB' "$CFG_CURRENT")" \ -tAc "SHOW server_version;")[ "${STORED_PG%%.*}" = "${CURRENT_PG%%.*}" ] || { echo "Error: PostgreSQL major version mismatch (backup: $STORED_PG, target: $CURRENT_PG)"; exit 1}
# TCP credential verificationRESTORE_DB_PASSWORD=$(jq -re '.services.db.environment.POSTGRES_PASSWORD' "$CFG_RESTORE")printf 'PGPASSWORD=%s\nPGCONNECT_TIMEOUT=10\n' "$RESTORE_DB_PASSWORD" > "$CRED_TMP"docker exec --env-file "$CRED_TMP" "$DB_CONTAINER" \ psql -h db -p 5432 -U "$RESTORE_DB_USER" -d "$(jq -re '.services.db.environment.POSTGRES_DB' "$CFG_RESTORE")" \ -tAc "SELECT 1;" > /dev/null || { echo "Error: TCP authentication failed with restored credentials"; exit 1}
echo "Preflight passed"
# ── Destructive operations ──
"${DC[@]}" stop nyravio
# Save current .envif [ -f .env ]; then ENV_SAVE=$(mktemp "./.env.pre-restore-XXXXXXXXXX") cp .env "$ENV_SAVE" echo "Existing .env saved as $ENV_SAVE"ficp "$BACKUP_DIR/env.backup" .envchmod 600 .env
# Restore database (atomic)docker exec -i "$DB_CONTAINER" psql -X --single-transaction -v ON_ERROR_STOP=1 \ -U "$RESTORE_DB_USER" -d "$(jq -re '.services.db.environment.POSTGRES_DB' "$CFG_RESTORE")" \ -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;" \ -f - < "$BACKUP_DIR/backup.sql"
# Recreate application container"${DC[@]}" create --no-build --pull never nyravio
# Restore uploadsNEW_CONTAINER=$("${DC[@]}" ps -q -a nyravio)"${DC[@]}" run --rm --pull never --no-deps --user root --entrypoint sh nyravio -c \ "find /app/data/uploads -mindepth 1 -maxdepth 1 -exec rm -rf {} +"docker cp - "$NEW_CONTAINER":/app/data/uploads/ < "$BACKUP_DIR/uploads.tar""${DC[@]}" run --rm --pull never --no-deps --user root --entrypoint sh nyravio -c \ "chown -R nyravio:nyravio /app/data/uploads"
# Start and verify"${DC[@]}" start nyravioPORT_MAPPING=$("${DC[@]}" port nyravio 8080)HOST_PORT="${PORT_MAPPING##*:}"echo "Waiting for readiness on port $HOST_PORT..."SECONDS=0TIMEOUT=120while [ "$SECONDS" -lt "$TIMEOUT" ]; do if curl -sf --connect-timeout 5 --max-time 10 \ "http://localhost:${HOST_PORT}/health/ready" > /dev/null 2>&1; then echo "Restore complete — application healthy (${SECONDS}s)" exit 0 fi sleep 2doneecho "Error: not ready within ${TIMEOUT}s"exit 1Preflight checks summary
Section titled “Preflight checks summary”The restore procedure performs these verifications before any changes:
- Required tools available
- All backup artifacts present
- Database dump checksum matches
- Uploads archive checksum matches
- Environment backup checksum matches
- Application image exists locally with matching ID
- Compose project identity matches
- Database configuration (user, name, passwords) matches
- Volume identities match
- PostgreSQL major version matches
- TCP credential verification succeeds
Limitations
Section titled “Limitations”- Database rollback is not automatic. Flyway migrations are forward-only.
- Image identity is verified. The image ID in metadata must match locally. Rebuilding from source does not guarantee the same ID.
- Encrypted credentials require the original
NYRAVIO_ADMIN_ENCRYPTION_KEY. - MCP master keys (
NYRAVIO_MCP_MASTER_KEYS) must also be preserved if MCP credentials are stored. - Uploads restore is not atomic. Re-run on failure before starting the application.
- Compatible deployment required. Cross-deployment restores are not supported.