Skip to content

Backups and restore

A backup is a compressed archive of the project directory: compose.yaml, .env, and whatever else lives alongside them. .git directories are left out, since a Git project fetches its history again on the next deploy. When the project has a Postgres, MySQL or MariaDB container, Windlass also takes a native dump and adds it to the archive as .windlass/backup/db_dump.sql.

Only Postgres, MySQL and MariaDB get a dump. From v0.64 the project’s named volumes are in the archive too (see Volumes); before v0.64 they were not. Data elsewhere outside the project directory, such as a bind mount of /srv/media, is not.

From v0.64, files in the project that another user owns, such as a database directory a container owns (uid 999, mode 0700) or uploads a web server writes as uid 33, are copied through Docker with their owners and modes, whether Windlass can read them or not. Docker runs a short-lived busybox container with no network for this, pinned by digest, and pulls the image the first time it is needed. Before v0.64 such a file failed the whole backup.

When the database’s dump is in the archive, the database service’s bind mounts inside the project that hold its data, such as ./data/postgres mounted at /var/lib/postgresql/data, are left out: the dump covers them, and a copy of a running database’s files is not a backup of it. Config and init files bound into the database stay in the archive. Each row lists what it left out, and a restore keeps those paths as they are. If Docker cannot copy an unreadable file, because it is not running or runs rootless or with user namespaces, which change file owners, a file it cannot read is left out and the row shows Some files left out with the reason, and one it can read is copied as plain files, which a restore gives to Windlass’s user.

From v0.64 a backup copies each named volume the compose file declares, through the same busybox helper, with the volume mounted read-only. Owners and modes are kept, and the files sit in the archive under .windlass/volumes/<key>/, where <key> is the volume’s name in the compose file. A restore never writes them into the project directory. Anonymous volumes are not copied. These volumes are left out, and the row says why:

  • a volume declared external, which belongs to something outside the project
  • a volume Docker does not have yet, because the project has never been deployed
  • one you turned off in the Backups tab, such as a cache; this applies to Back up now as well as the schedule
  • the volume the database keeps its data in, when its dump is in the backup: the dump covers it. Other volumes of the database service, such as WAL archives or init scripts, are copied

Without the dump, the database’s volume is copied instead, with a note saying so, since its files are then the only copy of the data. A second database in the project is never dumped, so its volumes are always copied, with a note. A copy of a running database’s files may not open cleanly; prefer a backup with a dump.

Volumes are copied while the project runs. A volume that a running service uses gets the note copied while web ran, naming the services, because a file being written during the copy may not match the rest. If a file changes size under the copy, that volume is marked not copied whole, the rest of the backup is still taken, the row shows Volume not copied whole, and the project goes on the dashboard’s Needs you list. Such a volume cannot be restored from that backup.

Before copying volumes, Windlass checks that the disk the archive goes to has room for the project and its volumes, before compression, and refuses the backup with both figures if not. A scheduled backup that runs for more than 4 hours is stopped and marked failed.

Back up now in the project’s Backups tab stores the archive on this server, in the backups directory beside the projects directory. Backups are listed with their status, and an incomplete one cannot be restored. A one-off backup to S3 is available through the API, POST /api/v1/projects/{name}/backups with {"destination": "s3"}.

The database container is recognised by its compose service name or its image, preferring one named exactly after the database (postgres, postgresql, postgis, pgvector, timescaledb, timescaledb-ha, mysql, mysql-server, mariadb, percona-server) over an image that only mentions it, such as bitnami/postgresql-repmgr. The dump runs inside that container with its own environment, so the credentials are found wherever you set them: in compose.yaml, in .env or in another env_file.

Postgres is dumped with pg_dump as POSTGRES_USER (default postgres) from POSTGRES_DB (default the user name, as the image does), using POSTGRES_PASSWORD when it is set. Bitnami’s POSTGRESQL_USERNAME, POSTGRESQL_DATABASE and POSTGRESQL_PASSWORD are read too. MySQL and MariaDB are dumped with mysqldump or mariadb-dump --all-databases as root, using MYSQL_ROOT_PASSWORD or MARIADB_ROOT_PASSWORD. A database whose credentials are not in its environment, such as a random root password or one read from a secrets file, cannot be dumped this way.

The dump is best effort and deliberately non-fatal. If the database container is not running or the dump fails, Windlass logs a warning saying the backup has no database dump and still takes the file archive. A backup that captured your compose file and environment is worth having even on a day the database was down.

Each row in the Backups tab says what it holds: Files and database dump, Files only when the dump failed, or Files; no database container found. Backups taken before v0.62 show Database dump not recorded, because earlier versions did not record it.

A project with volumes and no backup schedule shows on the dashboard’s Needs you list until you give it one. Staging projects and anonymous volumes are left out.

A dump that was written is not proof it loads. Back up and verify in the Backups tab, or {"verify": true} on POST /api/v1/projects/{name}/backups, loads the dump into a throwaway copy of the database and counts what arrived. The copy runs the live database container’s own image and environment, so it makes the same user and database, but it has no network, no mounts and a memory limit, and it is deleted with its storage when the check ends. It never connects to the live database. Postgres, MySQL and MariaDB are checked.

The check runs after the dump and before the archive is written. It reads the list of live tables from the database’s catalog, which scans no table. Then it loads the dump with psql -v ON_ERROR_STOP=1 or the mysql client, so the first error stops it, and counts the rows in every table. Each backup row then says one of:

  • Restore check passed, with the tables and rows counted, such as 14 tables, 52,301 rows.
  • Restore check failed: the dump did not load (the client’s ERROR line is shown, with everything from its first quote to its last blanked to '…' so no row value reaches an alert, and never the lines after it; when there is no ERROR line it says only that the load failed without saying why), the dump ends without the line its tool writes last so it was cut short, or a table in the live database is not in the restored copy.
  • Restore check could not run: the server had too little free memory or disk, or Windlass could not read how much it had, the check was stopped with its backup, the spooled dump could not be read, or the throwaway database did not start or answer within 5 minutes. The backup is fine; the dump is unchecked.
  • No restore check: there was no dump to check.

A failed or skipped check never fails the backup, which is kept either way. The latest check of each project decides the Needs you row and the backup_unverified alert. A later passed check clears it, and so does a check that finds no database. While the project’s schedule still checks, a backup in between that did not check leaves it showing; once the schedule’s check is set to Never, or the schedule is off, the next backup clears it.

The throwaway database may use 1,024 MiB unless an admin changes it under Settings, Backups. The check is skipped when the server has less free memory than that limit plus 256 MiB, so it cannot starve the live services. An empty MySQL 8.4 holds about 450 MiB on its own; Postgres and MariaDB need far less. A large database needs a larger limit, and the load takes about as long as a restore would. A throwaway that runs out of memory and stops mid-load reports could not run, not a failed check, and says to raise the limit.

The throwaway’s data lives under Docker’s data directory, often the live database’s disk, so the check is skipped unless that disk has twice the dump’s size plus 1 GiB free. One check runs at a time across the server, so two projects backing up together cannot both pass the memory and disk checks and then use twice the room; the second waits for the first.

Known limit: a Postgres dump that grants to roles the image does not create, such as extra roles made by hand, fails the check with role "..." does not exist. The dump itself is fine for a database that has those roles.

Set an interval of hourly, daily or weekly, a destination, and how many to retain. Check the dump restores runs the check above on a schedule: never (the default), once a week, or on every backup. Once a week checks the next backup that starts at least 7 days, less an hour, after the last backup whose check passed or failed, so a daily schedule checks every seventh backup even if a run starts a few minutes early. Windlass keeps that time on the schedule, so pruning old backups does not move it. A check that could not run is tried again at the next backup. After each scheduled run, whether its backup succeeded or failed, Windlass keeps the newest completed backups for that destination up to the retention count and deletes the rest. Backups taken with Back up now count towards that number and can be pruned with them. One exception: when every backup kept failed to copy a volume whole, the newest older backup that has it whole is kept as well, so a volume that fails on every run still has one copy. A backup that could not read the compose file to find the volumes counts as failing them all.

Pick a retention that matches what the archives cost you: they contain your .env, so they are secrets at rest wherever they land, unless you encrypt them (below).

An admin sets the bucket under Settings, Backups: the endpoint without the bucket name, a region (leave it blank for auto, which Cloudflare R2 expects), the bucket, an optional key prefix for sharing a bucket, and an access key pair. The keys are stored encrypted and never shown again. Then choose S3 as the destination of a project’s backup schedule.

Windlass uses path-style requests (endpoint/bucket/key), so anything speaking the S3 API works, including AWS S3, Cloudflare R2 and MinIO, which is what the wire tests run against. Until a bucket is set, S3 backups fail with a message saying so. An archive over 5 GiB, which volumes make likely, is uploaded in parts of at least 64 MiB; if a part fails, the upload is cancelled so the bucket keeps no stray parts.

Backups on a server are a hedge against a mistake. Backups off the server are a hedge against losing the server. If the data matters, use the second kind.

An admin can have every new backup encrypted with age before it is stored, on the server or in S3, under Settings, Backups, Encryption. Windlass holds only the public key. Anyone who gets the archive, from the bucket or a copy of the disk, needs your secret key to read it, and that includes the .env inside.

Make a key where you keep secrets, not on the server:

Terminal window
age-keygen -o windlass-backups.key

It prints the public key, age1.... Paste that into Public keys. You can add a second key as a recovery key, kept somewhere else, so losing one does not lose the backups. Then Check keys shows a short challenge for each key. Save each as challenge.age, run age -d -i windlass-backups.key challenge.age and paste the code it prints. Encryption turns on only when every code matches, which shows you hold each secret key; a mistyped key cannot leave every backup locked to a key nobody has. The check runs out after 30 minutes. Changing the keys works the same way, and Turn off makes new backups plain.

Each backup records the keys it was encrypted to, and the Backups tab marks it Encrypted. Backups already made keep the keys they were made with: turning encryption on does not encrypt old archives, and turning it off or changing the keys does not decrypt them. When a finished backup, of any project, has other keys than the finished backup before it, including encryption turned on or off, the backup_key_changed alert goes out once as that backup finishes and Needs you shows it for 7 days, so a key swapped by someone else does not go unseen. Windlass keeps the last keys used in the backups_encryption_last_used setting, so pruning old backups does not hide a change. The first backup after an upgrade is a change only when it is encrypted.

An encrypted archive ends in .tar.gz.age. Its SHA-256 is of the encrypted file, so the hash check works without the key. The database dump is written to a temporary file in the backups folder, plain, while the backup runs, as it was before encryption; it is deleted when the backup ends.

Keep the secret key safe and off the server. Without it an encrypted backup cannot be restored, by Windlass or anyone else.

To restore an encrypted backup, paste its secret key (the AGE-SECRET-KEY-1... line) into the restore dialog. Windlass checks it is one of the backup’s keys before it downloads or opens anything, then decrypts the whole archive into a temporary file in the backups folder and checks age’s authentication of every byte before the project is touched; a changed archive is refused. The temporary file is deleted when the restore ends, however it ends, and one a crash leaves is deleted when Windlass next starts. The key is used for that restore only: it is not stored, logged or written to the audit log.

Each backup from v0.64 records the SHA-256 of its archive as written. A restore checks it before anything in the project changes, after any download from S3, and refuses an archive whose hash differs: it was damaged on disk or in the bucket, or is not the file the backup wrote. Backups taken before v0.64 have no hash and restore as before.

Restore replaces the project directory with the archive: compose file, environment file, and the other files that were there, the database dump among them at .windlass/backup/db_dump.sql. Files added since the backup are removed. It extracts to a staging directory first, and the old directory is only deleted once the restored one is in place, so a damaged archive, or a file it cannot write, leaves the project as it was. The whole archive is read, its checksum included, before anything moves. Files and directories keep their modes. Symbolic links come back with their targets; a backup taken before v0.64 recorded none, so its links are not restored. A restore is refused while a backup of the project is running; try again when it finishes.

Files the backup copied through Docker go back through Docker with their owners and modes, without setuid or setgid bits. A backup without a database dump holds a copy of any database directory in the project, taken while the database ran; a restore replaces the running database’s files with it. Stop the database before restoring such a backup, and prefer one with a dump. If a restore stops part way and cannot put a kept path back, its error names the holding directory the path is in, and later restores of that project refuse until the files are moved back and the .windlass-carry-* directory is deleted. Paths the backup left out, such as the database’s files, are kept from the project as it is now rather than deleted, and so is a directory a container owns that the backup does not hold at all, such as a database started after the backup. Only directories are kept this way, not files: a file a container wrote since the backup goes with the restore, as any file the backup lacks does. So a directory planted since the backup also survives; after a break-in, check the project for directories you do not recognise before deploying it again. Files Windlass cannot delete itself, such as a database directory a container owns, are deleted through Docker. Where Docker cannot do that, the restore stops before changing anything and names up to three of them: moving them aside would start that database on an empty directory at the next deploy.

A mount inside the project stops a restore, since deleting through a mount would empty its source; so does a project directory that is itself a mount. Mounts made inside a container are not seen and need no check. An immutable file (chattr +i) is not caught: the restore completes, and what could not be deleted stays in a .windlass-replaced- directory beside the project, which the panel log names.

Deleting a project removes container-owned files through Docker the same way. A mount inside the project stops the delete before anything is removed.

A restore leaves volumes as they are unless you choose them. The restore dialog lists the volumes the backup copied whole, none ticked; through the API, send {"volumes": ["uploads"]} with the compose keys. A chosen volume’s contents are replaced with the copy in the backup, and files added since are removed. A volume that no longer exists is created again with its Docker name, driver, options and labels.

Stop every service that uses a chosen volume first. The restore refuses before changing anything while any container mounts it and is not stopped, in this project or another, while a stopped container of another project mounts it, or while the volume is labelled for another project, and names the container or project. It also refuses when Docker’s disk has no room for the volume’s copy, since the old contents stay inside the volume, in a .windlass-replaced- directory, until the restore is done. If any step fails, each volume gets its old contents back, and a volume the restore created is removed. A .windlass-replaced- directory still in a volume holds its contents from before an earlier restore, which either stopped before it finished (the server went down, say) or could not delete it. It may be the only copy of that data, so a restore refuses the volume until you move the directory out or delete it. A backup copies the directory with the rest of the volume, but a restore never puts it back. As with project files, setuid and setgid bits are dropped. Deploy afterwards to start the services again. While a restore changes a project, nothing else starts its services: Deploy and a push with auto-deploy on wait and start when the restore ends, and a rollback, a promotion to it, a staging copied from it, Start and Restart are refused. A restore does not begin while the project is deploying, starting or restarting, or while a new staging is copying its data. Stop is always allowed. If the restore fails, a deploy that waited for it is dropped, and the server log says so, since the project may be part restored: check it, then deploy. The hold is per project: a container of another project that mounts the same volume is caught only by the check just before each volume changes.

Restore does not redeploy. The running containers carry on as they were until you deploy, which is when the restored compose file and .env take effect. A Git project fetches its repository again on that deploy.

Restore needs the member role and is done in the panel. API tokens are refused, because it overwrites .env and everything else in the directory.

It does not load the dump back into your database. Restoring gives you the dump file in the project directory; putting its contents back is a deliberate act you perform, with the database in the state you intend:

Terminal window
cd /var/lib/windlass/projects/shop-api
docker compose up -d db
docker compose exec -T db psql -U postgres < .windlass/backup/db_dump.sql

This is deliberate. A restore that replayed a dump automatically would overwrite whatever the database currently holds, with no way to inspect it first, so Windlass restores the files and leaves that step to you.

Platform state lives in SQLite: users, sessions, audit history, deployment history, settings and encrypted credentials. Project backups do not contain it.

Restoring a project directory onto a fresh install gives you a working application, and Scan directory indexes it. Your accounts and history need a platform backup, which is a copy of the data directory taken while the service is stopped:

Terminal window
sudo systemctl stop windlass
sudo tar czf windlass-platform-$(date +%F).tar.gz -C /var/lib windlass
sudo systemctl start windlass

Keep that archive somewhere other than the machine it came from.