Backup and restore
Windshift keeps all state under /data: the SQLite database, uploaded attachments, plugins, AI prompt overrides and provider catalogs. A backup is a copy of that tree, plus a logical dump when you run PostgreSQL.
deploy/backup.sh in the core repository is the supported host-side workflow for the stock Docker Compose deployments. It is deliberately conservative: it validates what it is about to touch, fails closed when the deployment does not match a shape it understands, and refuses to run if another operation holds the lock.
It is not a general-purpose Docker or database recovery tool. For an unusual deployment — multiple app containers, extra mounts, an external database, a connection string, SSH-enabled instances — use your own database-specific procedure instead.
What the workflow covers
It backs up the complete configured /data tree and, for the supported PostgreSQL shape, a custom-format logical dump.
The helper image is pinned to the same Alpine digest used by deploy/coding-agent/Dockerfile. It runs with no network, a read-only root filesystem and no-new-privileges. Backup helpers receive Windshift volumes read-only. The restore helper receives a writable data volume only after all preflight checks and a local rollback snapshot have completed.
Supported deployment shape
- Exactly one Compose
windshiftcontainer using the stock/windshiftentrypoint. - Exactly one persistent mount at the configured data path. Additional mounts below that path are rejected, because deleting a mounted child can leave both restore and rollback incomplete.
- The backup directory and the rollback root must sit outside that mount's host source, so an archive cannot include or delete itself.
- No replicas.
SQLite is supported only when DB_PATH is below /data. An empty DB_PATH is rejected, because Windshift would otherwise fall back to a path outside the mounted data tree. The script also validates ATTACHMENT_PATH, PLUGIN_DIR, AI_PROMPTS_DIR, LLM_PROVIDERS_FILE and the comma-separated PLUGIN_DIRS when they are set; an empty PLUGIN_DIR is rejected for the same reason.
PostgreSQL is supported only when all of these hold:
DB_TYPE=postgresandPOSTGRES_CONNECTION_STRINGis unset.POSTGRES_HOSTequals the selected Compose service name exactly.POSTGRES_PORTis unset or5432.POSTGRES_USERandPOSTGRES_DBmatch that service's container environment exactly.- Exactly one PostgreSQL service container exists.
The automatic service candidates are postgres and db. Use --postgres-service NAME for another stock-style service; on restore that option overrides the manifest value.
Out of scope, and rejected: external databases, connection strings, non-default ports, custom database selection, replicas, SSH-enabled deployments, extra host mounts or persisted paths outside /data, environment values containing CR or LF, and the path overrides (--db, --attachment-path, --llm-providers, --ai-prompts-dir) or connection-string flags.
Use the same PostgreSQL major version for backup and restore, and restore only into the same Windshift image and schema generation that produced the backup, unless a separately verified migration plan says otherwise.
S3 attachment storage: when
STORAGE_BACKEND=s3, attachments live in the bucket rather than underATTACHMENT_PATH. This workflow still backs up the database, but it does not cover attachment blobs. Use the bucket's own versioning, replication or backup mechanism. See Attachment storage.
Create a backup
Run from the Compose directory:
cd deploy
./backup.sh backup /srv/windshift-backups/windshift-$(date -u +%Y%m%dT%H%M%SZ)The backup path must be an absolute, normalized host path without a colon, because it is passed to Docker's -v syntax. The created directory is mode 700 and contains:
data.tar.gz— the/datatreemanifest.env— paths, image and secret fingerprintchecksums.sha256— SHA-256 checksums of the artifactsdatabase.dump— custom-format PostgreSQL dump, when applicable
The script takes an atomic lock before stopping the app or writing files. If a lock exists, do not start another operation: first confirm nothing is running, then remove only the reported stale lock directory.
Checksums detect accidental corruption and incomplete copies. They do not authenticate a backup. Store backups on access-controlled, authenticated, encrypted media, and keep a copy outside the host.
The manifest stores a domain-separated SHA-256 fingerprint of the effective SSO_SECRET (or SESSION_SECRET when unset). This is a compatibility check, not a password verifier — weak secrets produce guessable fingerprints.
Pass --include-sso-secret only for an explicitly encrypted secret-recovery copy. It writes the raw effective secret as a mode-600 file named sso-secret inside the mode-700 backup and includes it in the checksum file. Treat that artifact as highly sensitive: never log it and never copy it to ordinary backup media.
Restore
Run from the same Compose directory:
cd deploy
./backup.sh restore --force /srv/windshift-backups/windshift-20260829T120000ZBefore stopping Windshift, restore rejects symlinked or non-regular input artifacts, copies approved artifacts into a private staging directory, and verifies only that staged snapshot from then on. The staged archive is checked in the same image that performs extraction: only regular files and directories are accepted, and absolute paths, parent paths, symbolic links, hard links, devices and FIFOs are rejected.
Restore compares the live secret fingerprint before changing any state. On a mismatch it fails closed and never writes a secret into Compose — configure the source secret in Compose or your secret manager first.
After the app stops, the script creates a mode-700 rollback directory under --rollback-root or WINDSHIFT_BACKUP_ROLLBACK_ROOT, defaulting to disk-backed /var/tmp. That directory must already exist and be writable, and needs space for a full compressed /data copy, the staging copy and, for PostgreSQL, a second logical dump. Do not place it on volatile /tmp unless losing it during a reboot is acceptable.
For PostgreSQL the rollback contains both /data and a pre-restore database dump. Retained rollback artifacts get SHA-256 checksums, and custom-format dumps are structurally validated with pg_restore --list before being relied on. The target restore uses pg_restore --single-transaction --exit-on-error, which cleans and restores the objects in the archive — not necessarily unrelated database objects.
The rollback is retained until the started application is healthy. When Docker exposes a health check the script waits for it for up to WINDSHIFT_BACKUP_HEALTH_TIMEOUT seconds (default 90); otherwise it runs /windshift healthcheck through Compose until the deadline. Raise that timeout before restoring when startup or migrations can legitimately take longer than 90 seconds.
If the target is unhealthy, the script restores both rollback data and PostgreSQL before trying the old state. If PostgreSQL state is uncertain because of an interruption or a failed database command, Windshift stays stopped and the error retains both the rollback and staged paths. The recovery lock also stays in place, because a detached server-side pg_restore may still be running — remove it only after confirming nothing is active and resolving the database state.
If Windshift was already stopped before the restore, the script cannot health-check or auto-start it. It reports success with the retained rollback path so you can validate a manual start before removing it.
The command uses a 60-second Compose stop timeout. An interrupted command, host reboot or Docker failure can still leave the service stopped, so read the printed recovery paths before restarting.
Manual emergency recovery
This is a destructive emergency procedure. Leave Windshift stopped and first copy every reported stage and rollback directory to immutable, access-controlled storage. Use only the same Windshift image and schema generation, and the same PostgreSQL major version.
Validate the retained checksums and data archive in a separate preflight before stopping or deleting anything. Use the host's SHA-256 tool and the exact pinned helper image:
cd deploy
(cd "$ROLLBACK_DIR" && sha256sum -c checksums.sha256)
docker run --rm --network none --read-only --security-opt no-new-privileges -v "$ROLLBACK_DIR:/backup:ro" alpine:3.21@sha256:48b0309ca019d89d40f670aa1bc06e426dc0931948452e8491e3d65087abc07d sh -ec '
test -s /backup/data.tar.gz
tar -tzf /backup/data.tar.gz >/dev/null
tar -tvzf /backup/data.tar.gz >/dev/null
tar -tzf /backup/data.tar.gz | awk '\''{
path = $0
if (path == "./") key = "."
else {
if (substr(path, 1, 2) != "./") exit 1
path = substr(path, 3)
if (path == "" || path ~ /(^|\/)\.($|\/)/ || path ~ /(^|\/)\.\.($|\/)/ || path ~ /\/\//) exit 1
sub(/\/$/, "", path)
if (path == "") exit 1
key = path
}
if (seen[key]++) exit 1
count++
} END { if (!count) exit 1 }'\''
if tar -tvzf /backup/data.tar.gz | grep -Eqv "^[-d]"; then exit 1; fi
if tar -tvzf /backup/data.tar.gz | grep -E "^-.* -> "; then exit 1; fi
'If the host provides shasum instead, use shasum -a 256 -c checksums.sha256. Do not continue unless every command succeeds.
For PostgreSQL, validate the retained dump before touching /data. Set POSTGRES_SERVICE to the confirmed service name and keep remote_dump for the restore step:
POSTGRES_SERVICE=postgres
db_id=$(docker compose ps --all -q "$POSTGRES_SERVICE")
[ "$(printf '%s\n' "$db_id" | sed '/^$/d' | wc -l | tr -d ' ')" = 1 ] || exit 1
remote_dump=/tmp/windshift-manual-rollback-$.dump
docker cp "$ROLLBACK_DIR/database-before.dump" "$db_id:$remote_dump"
docker compose exec -T -e REMOTE_DUMP="$remote_dump" "$POSTGRES_SERVICE" sh -ec 'pg_restore --list "$REMOTE_DUMP" >/dev/null'For /data, resolve exactly one Windshift container before stopping it:
cd deploy
windshift_id=$(docker compose ps --all -q windshift)
[ "$(printf '%s\n' "$windshift_id" | sed '/^$/d' | wc -l | tr -d ' ')" = 1 ] || exit 1
mount_destinations=$(docker inspect -f '{{range .Mounts}}{{println .Destination}}{{end}}' "$windshift_id")
[ "$(printf '%s\n' "$mount_destinations" | grep -Fxc /data)" = 1 ] || exit 1
if printf '%s\n' "$mount_destinations" | grep -Eq '^/data/'; then exit 1; fi
docker compose stop --timeout 60 windshift || exit 1
[ "$(docker compose ps --all -q windshift)" = "$windshift_id" ] || exit 1
[ "$(docker inspect -f '{{.State.Running}}' "$windshift_id")" = false ] || exit 1
docker run --rm --network none --read-only --security-opt no-new-privileges --volumes-from "$windshift_id" -v "$ROLLBACK_DIR:/backup:ro" alpine:3.21@sha256:48b0309ca019d89d40f670aa1bc06e426dc0931948452e8491e3d65087abc07d sh -ec 'find /data -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +; tar -C /data -xzf /backup/data.tar.gz'For PostgreSQL, restore the already validated dump only after confirming the target database again:
docker compose exec -T -e REMOTE_DUMP="$remote_dump" "$POSTGRES_SERVICE" sh -ec 'pg_restore --clean --if-exists --no-owner --no-privileges --single-transaction --exit-on-error -U "$POSTGRES_USER" -d "$POSTGRES_DB" "$REMOTE_DUMP"'
docker compose exec -T "$POSTGRES_SERVICE" rm -f "$remote_dump"The PostgreSQL rollback cleans the objects listed in its dump but may leave unrelated objects created by a newer schema. Remove any container path printed as remote= once the database state is recovered and the retained dump is preserved elsewhere. Only then start Windshift and run its health check.
Related
- System requirements for disk sizing and the S3 attachment backend.
- Production-ready self-hosting for the full deployment checklist.
- Environment variables for
DB_PATH,ATTACHMENT_PATHand the storage settings.