Backup
A complete Nyravio backup consists of four artifacts stored together in a dedicated directory:
| Artifact | File | Description |
|---|---|---|
| Database dump | backup.sql |
Full PostgreSQL schema and data |
| Uploads archive | uploads.tar |
Tar archive of user-uploaded files |
| Environment file | env.backup |
Contains encryption keys and secrets |
| Metadata | backup-metadata.json |
Checksums, image identity, versions (no secrets) |
Create a backup
Section titled “Create a backup”Each backup is written to an atomically unique directory created with restricted permissions (umask 077) and a unique name via mktemp. By default, backups are stored in $HOME/nyravio-backups/. Override with NYRAVIO_BACKUP_DIR — ensure it points outside the project tree.
set -euo pipefailumask 077
# ── Configuration ──BACKUP_ROOT="${NYRAVIO_BACKUP_DIR:-$HOME/nyravio-backups}"mkdir -p "$BACKUP_ROOT"BACKUP_DIR=$(mktemp -d "$BACKUP_ROOT/nyravio-backup-XXXXXXXXXX")
# 1. Save your .env file FIRST (contains encryption keys)cp .env "$BACKUP_DIR/env.backup"ENV_SHA256=$(sha256sum "$BACKUP_DIR/env.backup" | awk '{print $1}')
# 2. Identify the running application containerAPP_CONTAINER=$(docker compose ps -q nyravio)if [ -z "$APP_CONTAINER" ]; then echo "Error: nyravio application container not running"; exit 1fi
# 3. Capture image identity from the actual containerIMAGE_ID=$(docker inspect --format='{{.Image}}' "$APP_CONTAINER")APP_IMAGE=$(docker inspect --format='{{.Config.Image}}' "$APP_CONTAINER")
# 4. Find the database containerDB_CONTAINER=$(docker compose ps -q db)if [ -z "$DB_CONTAINER" ]; then echo "Error: database container not found"; exit 1fiDB_USER=$(docker exec "$DB_CONTAINER" printenv POSTGRES_USER)DB_NAME=$(docker exec "$DB_CONTAINER" printenv POSTGRES_DB)
# 5. Stop the application for a consistent snapshotdocker compose stop nyravio
# 6. Full database dumpdocker exec "$DB_CONTAINER" pg_dump -U "$DB_USER" -d "$DB_NAME" \ --clean --if-exists > "$BACKUP_DIR/backup.sql"
# 7. Verify the dump is not emptyDUMP_SIZE=$(wc -c < "$BACKUP_DIR/backup.sql")if [ "$DUMP_SIZE" -lt 100 ]; then echo "Error: backup file suspiciously small ($DUMP_SIZE bytes)"; exit 1fiDUMP_SHA256=$(sha256sum "$BACKUP_DIR/backup.sql" | awk '{print $1}')
# 8. Archive uploadsdocker cp "$APP_CONTAINER":/app/data/uploads/. - > "$BACKUP_DIR/uploads.tar"UPLOADS_SHA256=$(sha256sum "$BACKUP_DIR/uploads.tar" | awk '{print $1}')UPLOADS_SIZE=$(wc -c < "$BACKUP_DIR/uploads.tar")
# 9. Capture PostgreSQL versionPG_VERSION=$(docker exec "$DB_CONTAINER" psql -X -U "$DB_USER" -d "$DB_NAME" -tAc \ "SHOW server_version;")
# 10. Write metadata LAST as completion marker (no secrets)cat > "$BACKUP_DIR/backup-metadata.json" <<EOF{ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)", "nyravio_image": "$APP_IMAGE", "image_id": "$IMAGE_ID", "pg_version": "$PG_VERSION", "db_user": "$DB_USER", "db_name": "$DB_NAME", "dump_sha256": "$DUMP_SHA256", "dump_size_bytes": $DUMP_SIZE, "uploads_sha256": "$UPLOADS_SHA256", "uploads_size_bytes": $UPLOADS_SIZE, "env_sha256": "$ENV_SHA256"}EOF
echo "Backup complete: $BACKUP_DIR"echo " SQL dump: $DUMP_SIZE bytes, sha256=${DUMP_SHA256:0:16}..."echo " Uploads: $UPLOADS_SIZE bytes (tar archive)"echo " Image: $APP_IMAGE ($IMAGE_ID)"
# 11. Restart the applicationdocker compose start nyravioYour backup directory will contain:
nyravio-backup-a1b2c3d4e5/ backup.sql # Database dump backup-metadata.json # Checksums, image ID, versions (no secrets) uploads.tar # Archived user-uploaded files (tar) env.backup # Environment with encryption keys (KEEP SECURE)Preserving the application image
Section titled “Preserving the application image”The restore procedure requires the exact Docker image (verified by ID) recorded in backup metadata. Rebuilding from the same source does not guarantee an identical image ID — Docker builds are not deterministic.
Prebuilt images
Section titled “Prebuilt images”Retain the immutable registry digest and pull before restoring:
docker pull ghcr.io/lexprofi/nyravio@sha256:DIGESTSource-built images
Section titled “Source-built images”Save the image to a tar archive. Verify the tag still resolves to the running image:
# APP_IMAGE and IMAGE_ID are from the backup procedure aboveTAG_ID=$(docker image inspect --format='{{.Id}}' "$APP_IMAGE" 2>/dev/null) || TAG_ID=""if [ "$TAG_ID" != "$IMAGE_ID" ]; then SHORT_ID="${IMAGE_ID#sha256:}" SHORT_ID="${SHORT_ID:0:12}" echo "Warning: $APP_IMAGE no longer points to $IMAGE_ID — tagging for backup" docker tag "$IMAGE_ID" "nyravio:backup-${SHORT_ID}" APP_IMAGE="nyravio:backup-${SHORT_ID}"fidocker save -o nyravio-image-backup.tar "$APP_IMAGE"sha256sum nyravio-image-backup.tar > nyravio-image-backup.tar.sha256To restore the image before running the restore procedure:
sha256sum -c nyravio-image-backup.tar.sha256docker load -i nyravio-image-backup.tarStore image archives outside the project tree alongside your backups.
Backup validation
Section titled “Backup validation”Run the automated backup test script to verify your backup/restore pipeline:
bash scripts/ci/backup-test.shThis creates an isolated environment, writes test data, creates a backup, restores it, and verifies data integrity including encrypted credential decryption.