# Off-site recovery

Source: https://docs.neode.sk/operations/backup/offsite-recovery/
Last updated: 2026-12-03

> Back up the database, configuration and session recordings every day into two encrypted restic repositories, and restore them into a fresh install.

`neodesk-server backup --offsite` copies everything a lost server needs into
two [restic](https://restic.net) repositories on storage away from it: the
SQLite or PostgreSQL database, the configuration, and the bytes of the
[session recordings](https://docs.neode.sk/console/recordings.md), also those in an S3 bucket.
`neodesk-server restore --offsite` puts them into a fresh install. restic
encrypts both repositories with a password of its own.

The two repositories keep the data apart from the keys:

- The **data repository** holds the database, the configuration and the
  recordings.
- The **key repository** holds the key of the recordings
  (`recordings.key`), the key of the saved device passwords, the key of the
  secrets of [webhooks](https://docs.neode.sk/console/settings/webhooks.md) and notification
  channels (`.integrations_key`), the server's key pair, the TLS private keys
  and the configuration that can hold passwords.

Keep the access to the key repository apart from the access to the data
repository. Each data snapshot names the key snapshot it belongs to, and a
restore takes that one.

The console's [Backups page](https://docs.neode.sk/operations/backup.md#the-backup-page-in-the-console)
and the installers' backups stay as they are. Off-site recovery is for losing
the whole server.

## What you need

- restic 0.18 or newer on the server and on the machine you restore on. The
  backup refuses an older restic, such as the 0.17 package of Ubuntu and
  Debian, before it writes anything. Take the release binary from
  [restic's releases](https://github.com/restic/restic/releases) when your
  system's package is older.
- With PostgreSQL, `pg_dump` and `psql` of the server's PostgreSQL version or
  newer.
- Two places for repositories, best with two storage services or at least two
  accounts: restic writes to S3-compatible storage, SFTP, its REST server and
  others. Each repository gets its own password and its own credentials.
- A safe place outside the server, such as a password manager, for both
  repository addresses, both passwords and the way into the storage accounts.
  Without them nobody can restore.

## Set up the daily backup

The steps are for a Linux install with the installer's folders, which runs as
the account `neodesk`. Run them as root.

1. Make the folder for the private files and one env file per repository.
   Both use the same names with their own values. For the data repository on
   an S3-compatible service:

   ```bash
   sudo install -d -m 0750 -o root -g neodesk /etc/neodesk/private
   sudo tee /etc/neodesk/private/data-repository.env >/dev/null <<'EOF'
   RESTIC_REPOSITORY=s3:https://<storage-host>/<bucket>/production
   RESTIC_PASSWORD_FILE=/etc/neodesk/private/data-repository.password
   AWS_ACCESS_KEY_ID=<access-key>
   AWS_SECRET_ACCESS_KEY=<secret-key>
   AWS_DEFAULT_REGION=<region>
   EOF
   ```

   Put the storage service's address and a bucket for the data in place of
   `<storage-host>` and `<bucket>`, the data repository's credentials in place
   of `<access-key>` and `<secret-key>`, and the storage's region in place of
   `<region>`. Write `key-repository.env` the same way, with the other repository, the
   other storage account and `key-repository.password`. Put each password
   into its file and let the account `neodesk` read the files:

   ```bash
   sudo chown root:neodesk /etc/neodesk/private/*
   sudo chmod 0640 /etc/neodesk/private/*
   ```

2. Create each repository once:

   ```bash
   sudo bash -c 'set -a; . /etc/neodesk/private/data-repository.env; restic init'
   sudo bash -c 'set -a; . /etc/neodesk/private/key-repository.env; restic init'
   ```

3. Write `/etc/neodesk/offsite.json`. `installation` is a name for this
   server; the restore asks for the same one.

   ```json
   {
     "installation": "production",
     "data_repository_env": "/etc/neodesk/private/data-repository.env",
     "key_repository_env": "/etc/neodesk/private/key-repository.env",
     "staging_directory": "/var/lib/neodesk-offsite",
     "configuration_files": [],
     "environment_keys": []
   }
   ```

   | Key | What it is |
   |---|---|
   | `installation` | The name of this server in the repositories. |
   | `data_repository_env`, `key_repository_env` | The env files of step 1, with absolute paths. |
   | `staging_directory` | Where the backup puts its copy before restic takes it. It must exist and have room for the database and the recordings; the backup account can read what is in it until the backup is done, so put it on an encrypted volume. Left out, the system's temporary folder. |
   | `configuration_files` | Absolute paths of other files to keep, such as a reverse proxy's configuration. A restore puts them under `deployment/`. |
   | `environment_keys` | Names of variables from the server's environment to keep besides its env file. |

4. Install the two systemd units. They are in the server's repository, in
   `deploy/systemd/` of the release's tag:

   ```bash
   v=4.0.0-rc.2
   for f in neodesk-offsite-backup.service neodesk-offsite-backup.timer; do
     sudo curl -fsSL -o /etc/systemd/system/$f \
       https://raw.githubusercontent.com/neodeskapp/neodesk/v$v/deploy/systemd/$f
   done
   ```

   The service runs as `neodesk` in `/opt/neodesk`. It names the env file
   `/opt/neodesk/.env`, but the Linux installer keeps it in
   `/opt/NeoDeskConsole/.env`, so point it there in
   `/etc/neodesk/offsite-source.env`, which the service reads after its own
   settings:

   ```bash
   echo 'NEODESK_ENV_FILE=/opt/NeoDeskConsole/.env' | sudo tee /etc/neodesk/offsite-source.env
   ```

5. Run the first backup, look for the snapshot ID in its log, then switch the
   timer on:

   ```bash
   sudo systemctl daemon-reload
   sudo systemctl start neodesk-offsite-backup.service
   sudo journalctl -u neodesk-offsite-backup.service -n 25
   sudo systemctl enable --now neodesk-offsite-backup.timer
   ```

The timer runs the backup every day at about 02:00 UTC and catches up on a run
it missed while the server was off. The backup runs while NeoDesk serves. A
recording that is deleted while the backup copies it can make the run fail;
the next run takes it again, and the snapshots before stay.

With Docker or Kubernetes, run the same command once a day as a job of its own:
the server image with restic added, the server's environment, its data volume
and the database connection, and the two env files. Have a failed or missed
run alert someone.

When you prune old snapshots with `restic forget`, keep every key snapshot a
data snapshot you keep still names. Each data snapshot names it as
`key_snapshot` in `/neodesk-recovery/recovery.json`.

## Restore on a fresh server

1. Install the same NeoDesk version as the lost server, restic and, for
   PostgreSQL, its tools. Put the two repository env files and their
   passwords back from your safe place, and write `offsite.json` with the same
   `installation` as before.
2. For PostgreSQL, make an empty database for NeoDesk and give its address in
   `NEODESK_RESTORE_DATABASE_URL` or with `--db`. The restore loads the dump
   in one transaction. SQLite comes back as a file in the target folder.
3. Restore into a new, empty folder with room for everything:

   ```bash
   sudo /opt/neodesk/neodesk-server restore --offsite /etc/neodesk/offsite.json \
     --target /srv/neodesk-recovered
   ```

   Without `--snapshot` it takes the newest complete backup; `--snapshot`
   with the full ID a backup printed takes that one. Give the folder to the
   account the server runs as.

   The folder gets `server/` with the database, the key pair and the other
   key files, `console/.env`, the console's `data/` and `config/`, and
   `recovery.json`, which names the snapshots it came from.
4. The command prints the path of the restored `console/.env`, whose paths
   already point into the new folder. Check the addresses of outside services
   in it, then start the server with `NEODESK_ENV_FILE` set to that file and
   the restored `server/` folder as its working directory.
5. Check it: on [Recordings](https://docs.neode.sk/console/recordings.md), play a recording,
   one that was in S3 if you had any, and connect to a test device with a
   saved password.

The restored server plays the recordings from its own disk, also those that
were in S3, and keeps new recordings there until you change the
[recording storage](https://docs.neode.sk/console/settings/recordings.md). To practise a
recovery, restore onto a machine that production clients can't reach and that
has no access to the original bucket.
