Skip to content

Back up and restore

At the end of this page, you know how to turn on the nightly backup, how to take a dump by hand, and what the restore status is.

The backup runs in the backup profile. It writes encrypted dumps every night to the volume dmsforall_dfa_postgres_backups.

  1. Put an age public key in .env:

    Terminal window
    AGE_CLE_PUBLIQUE=age1...
  2. Start the profile:

    Terminal window
    docker compose --profile backup up -d

Keep the age private key off this server. Without it, the backups cannot be read. The backup is built from the repository, so keep a clone of it on the server.

The backup hour is set with HEURE_SAUVEGARDE (default 03:15) and the time zone with DFA_TIMEZONE (default UTC).

For a one-off copy of the database, use pg_dump in the Postgres container:

Terminal window
docker compose exec postgres pg_dump -U dfa -Fc dfa > dfa-$(date +%Y%m%d).dump

Store the file encrypted and outside the server.

  • The uploaded documents, in the volume dmsforall_dfa_api_uploads. Check the backup scope before you rely on it.
  • The Redis data. Queues and short-lived state are recreated.

A restore brings the database back to the time of the backup. Everything written after that backup is lost.

  1. Stop the api and worker services, so that nothing writes to the database.
  2. Restore the dump into an empty database on a separate machine first, and check the result.
  3. Only then restore on the production server.