Off-site recovery
Copy as Markdownneodesk-server backup --offsite copies everything a lost server needs into
two restic repositories on storage away from it: the
SQLite or PostgreSQL database, the configuration, and the bytes of the
session recordings, 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 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 and the installers' backups stay as they are. Off-site recovery is for losing the whole server.
- 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 when your system's package is older.
- With PostgreSQL,
pg_dumpandpsqlof 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.
The steps are for a Linux install with the installer's folders, which runs as
the account neodesk. Run them as root.
-
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:
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> EOFPut 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>. Writekey-repository.envthe same way, with the other repository, the other storage account andkey-repository.password. Put each password into its file and let the accountneodeskread the files:sudo chown root:neodesk /etc/neodesk/private/* sudo chmod 0640 /etc/neodesk/private/* -
Create each repository once:
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' -
Write
/etc/neodesk/offsite.json.installationis a name for this server; the restore asks for the same one.{ "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 installationThe name of this server in the repositories. data_repository_env,key_repository_envThe env files of step 1, with absolute paths. staging_directoryWhere 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_filesAbsolute paths of other files to keep, such as a reverse proxy's configuration. A restore puts them under deployment/.environment_keysNames of variables from the server's environment to keep besides its env file. -
Install the two systemd units. They are in the server's repository, in
deploy/systemd/of the release's tag: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 doneThe service runs as
neodeskin/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:echo 'NEODESK_ENV_FILE=/opt/NeoDeskConsole/.env' | sudo tee /etc/neodesk/offsite-source.env -
Run the first backup, look for the snapshot ID in its log, then switch the timer on:
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.
-
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.jsonwith the sameinstallationas before. -
For PostgreSQL, make an empty database for NeoDesk and give its address in
NEODESK_RESTORE_DATABASE_URLor with--db. The restore loads the dump in one transaction. SQLite comes back as a file in the target folder. -
Restore into a new, empty folder with room for everything:
sudo /opt/neodesk/neodesk-server restore --offsite /etc/neodesk/offsite.json \ --target /srv/neodesk-recoveredWithout
--snapshotit takes the newest complete backup;--snapshotwith 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'sdata/andconfig/, andrecovery.json, which names the snapshots it came from. -
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 withNEODESK_ENV_FILEset to that file and the restoredserver/folder as its working directory. -
Check it: on Recordings, 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. To practise a recovery, restore onto a machine that production clients can't reach and that has no access to the original bucket.