Backups & Restore

All of Vela's state lives in one data directory — and, for R2, one bucket prefix. velad backup produces a consistent snapshot of it. How complete that snapshot is depends on the storage backend.

Backups are sensitiveA backup contains private files, API key hashes and the link signing keys. Anyone with a backup can forge valid signed links for its data. Store backups encrypted or on access-controlled storage; the backup directory itself is created with mode 0700.

Filesystem backups

With VELA_STORAGE=fs, a backup is complete and can be taken while the server runs:

$ docker exec vela velad backup /data/backups/2026-10-13 --verify
Backup written to /data/backups/2026-10-13: 5 object(s), 5 blob(s): 5 linked, 0 copied, all verified.
/srv/vela/backups/2026-10-13/
├── vela.db            # SQLite snapshot (VACUUM INTO)
└── blobs/             # every blob referenced by live objects and the trash
    ├── r7/c4/01m4tscd50ry5wfktp4mx4r7c4
    └── …

How it stays consistent:

  • The destination must not exist or must be empty.
  • The database is copied with SQLite's VACUUM INTO, which produces a consistent snapshot even under concurrent writes.
  • A renewable backup lease stops the blob collector — in every process — from deleting anything until the last blob is copied, so a file overwritten during the backup cannot lose the content the snapshot points to.
  • Each referenced blob is hard-linked when the destination is on the same filesystem (instant, no extra space) or copied otherwise, and its size is checked. --verify additionally recomputes every SHA-256, reading all data.
  • A missing or damaged blob fails the backup, and partial output is removed. A backup is never silently incomplete.
  • Only one backup or migration runs at a time.

Hard-linked backupsHard links share data with the live store. Vela never modifies a blob in place, so they are safe — but treat them as immutable, and copy them off the host (for example with rsync -aH or restic) so they survive a disk failure.

Scheduling

A nightly backup with a systemd timer on the host, keeping 14 days:

#!/usr/bin/env bash
set -euo pipefail
name=$(date -u +%Y%m%dT%H%M%SZ)
docker exec vela velad backup "/data/backups/$name" --verify
# keep 14 days of snapshots
find /srv/vela/backups -mindepth 1 -maxdepth 1 -type d -mtime +14 -exec rm -rf {} +
# then ship /srv/vela/backups/$name off the host with your tool of choice
[Unit]
Description=Nightly Vela backup

[Timer]
OnCalendar=*-*-* 04:00:00
RandomizedDelaySec=15m
Persistent=true

[Install]
WantedBy=timers.target
[Unit]
Description=Vela backup
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/vela-backup.sh
sudo systemctl daemon-reload
sudo systemctl enable --now vela-backup.timer

Alternative: cold copy

Stopping the container and copying /srv/vela as a whole is also a valid backup, because all state is in that directory. velad backup just avoids the downtime and verifies the result.

R2 / S3 backups

With VELA_STORAGE=r2, velad backup writes only the SQLite snapshot. Bucket contents are neither copied nor checked, and --verify is rejected. A metadata snapshot alone is not sufficient for disaster recovery: you need a database snapshot and a copy of the bucket prefix that describe the same moment.

The reliable way to get that pair is to stop the server (so neither uploads nor the collector change anything), take the database snapshot with a one-shot container, copy the bucket, and start Vela again:

#!/usr/bin/env bash
set -euo pipefail
ENV_FILE=/etc/vela/vela.env
DEST=/srv/vela-backups
ts=$(date -u +%Y%m%dT%H%M%SZ)

# Read single values from the env file without sourcing it.
envval() { grep -E "^$1=" "$ENV_FILE" | tail -n1 | cut -d= -f2-; }
bucket=$(envval VELA_R2_BUCKET)
prefix=$(envval VELA_R2_PREFIX); prefix=${prefix:-blobs/}
endpoint=$(envval VELA_R2_ENDPOINT)
[ -n "$endpoint" ] || endpoint="https://$(envval VELA_R2_ACCOUNT_ID).r2.cloudflarestorage.com"

image=$(docker inspect -f '{{.Config.Image}}' vela)
install -d -m 0700 "$DEST/db" "$DEST/blobs"

docker stop vela
trap 'docker start vela' EXIT          # always restart, even on failure

# 1. Metadata snapshot, written by a one-shot container into the data directory
#    (only that directory is writable by UID 65532), then moved out.
docker run --rm --env-file "$ENV_FILE" \
  --mount type=bind,src=/srv/vela,dst=/data \
  "$image" backup "/data/.backup-$ts"
mv "/srv/vela/.backup-$ts" "$DEST/db/$ts"

# 2. Bucket copy with rclone, configured from the environment (no rclone.conf with secrets).
export RCLONE_CONFIG=/dev/null
export RCLONE_CONFIG_R2_TYPE=s3 RCLONE_CONFIG_R2_PROVIDER=Cloudflare
export RCLONE_CONFIG_R2_ENDPOINT="$endpoint" RCLONE_CONFIG_R2_NO_CHECK_BUCKET=true
export RCLONE_CONFIG_R2_ACCESS_KEY_ID="$(envval VELA_R2_ACCESS_KEY_ID)"
export RCLONE_CONFIG_R2_SECRET_ACCESS_KEY="$(envval VELA_R2_SECRET_ACCESS_KEY)"
rclone copy "r2:$bucket/$prefix" "$DEST/blobs/"

Using rclone copy (not sync) into one cumulative directory means older database snapshots stay restorable: blobs removed from the bucket since are still in the mirror. Run the script as root from a systemd timer like the one above. Downtime lasts as long as the bucket copy; incremental rclone copy runs are fast once the mirror exists.

The bucket token used for backups only needs read access. Consider a separate read-only R2 token for the backup job.

Restoring

Restoration always happens with Vela stopped.

  1. Stop the server

    docker stop vela
  2. Restore the database

    Replace vela.db and remove stale WAL files — they belong to the old database and must not be replayed onto the restored one:

    cd /srv/vela
    sudo rm -f vela.db-wal vela.db-shm
    sudo cp /srv/vela/backups/2026-10-13/vela.db vela.db
    sudo chown 65532:65532 vela.db && sudo chmod 600 vela.db
  3. Restore the contents

    Filesystem: replace blobs/ with the backup's blobs/ (keep ownership 65532, directories 0755, files 0644):

    sudo rm -rf /srv/vela/blobs
    sudo cp -a /srv/vela/backups/2026-10-13/blobs /srv/vela/blobs
    sudo chown -R 65532:65532 /srv/vela/blobs

    R2: restore the bucket prefix from the matching bucket copy, e.g. rclone copy /srv/vela-backups/blobs/ r2:vela-store/blobs/.

  4. Start with the same backend settings

    docker start vela
    vela ls -r | head

    Use the same VELA_STORAGE, bucket and prefix as when the backup was taken.

Test your restores

A backup you have never restored is a hope, not a backup. Periodically restore into a scratch container with a different data directory and port, and spot-check a few files:

mkdir -p /tmp/vela-restore && cp -a /srv/vela/backups/2026-10-13/. /tmp/vela-restore/
sudo chown -R 65532:65532 /tmp/vela-restore
docker run --rm -p 127.0.0.1:18080:8080 \
  --mount type=bind,src=/tmp/vela-restore,dst=/data \
  -e VELA_PUBLIC_URL=http://127.0.0.1:18080 xchunk/vela:0.9.0

Your existing API keys work against the restored copy, because key hashes are part of the database.