Hearth documentation

Backups and restore

Hearth can back itself up. It uses restic, so every backup is encrypted, deduplicated and compressed, and a plain restic can open the repository without Hearth. You set it up in Administration, Backups. If you already back up the server another way, you can leave this off and follow Backing up by hand instead, or run both: two independent copies are better than one.

People can also copy their own files to storage of their own, in Settings, Backups. That is described at the end of this page.

Turning backups on

The server's backup needs two settings. The image ships restic, so on a standard install:

BACKUP_RESTIC: /usr/local/bin/restic
BACKUP_WORK_DIR: /data/backup-work

BACKUP_WORK_DIR holds restic's cache and a restore's staging area. Put it on disk, for example a named volume, not in memory. Without BACKUP_RESTIC, Administration, Backups says "Backups are off on this server (BACKUP_RESTIC)."

Other settings you may want:

See the configuration reference for every value.

Where the backup goes

  1. Go to Administration, Backups.
  2. Under Where, choose a Kind:
    • Folder on this server: a folder inside one of BACKUP_LOCAL_ROOTS.
    • S3-compatible (MinIO and others): endpoint, bucket, access key and secret key, with an optional region and folder in the bucket.
    • Backblaze B2: region (such as us-east-005), bucket, key ID and application key.
    • Scaleway Object Storage: region (such as fr-par), bucket, access key and secret key.
    • SFTP: host, username, a password or a private key, and the host key fingerprint (SHA256). Hearth refuses a server whose key does not match.
  3. Select Save, then Check. Check makes the repositories if they do not exist yet and opens them.

The target's passwords and keys are stored sealed with the master key.

When, and how long backups are kept

Under When:

Select Save. The line under the form shows the time zone the times are read in.

Backups, restore tests and restores run as background jobs, one at a time across all Hearth containers, at the lowest processor and disk priority.

What is in each backup

The section In each backup lists every part with what it holds and what is left out. Each module declares its own part, so a new module's data is backed up without any change on your side.

The master key is never in the backup. See The master key copy.

The master key copy

Files encrypted at rest cannot be read without the master key, and a backup that held the key next to the data would protect nothing. Hearth can keep a copy of the key encrypted to an age key that only you hold:

  1. On a computer you trust, make an age key pair:

    age-keygen -o age-identity.txt
    

    The file holds the private identity. The line starting age1 is the public key.

  2. Paste the public key into Master key copy: age public key and select Save.

  3. Keep age-identity.txt offline, away from the server and away from the restore kit.

The copy goes into a second repository beside the first, with its own password. Even someone who has the backup and its restore kit cannot open files encrypted at rest without your age identity.

The restore kit

Select Restore kit to download hearth-restore-kit.json. It says where the backup is and holds the target's secrets and the repositories' passwords: everything needed to read the backup, except the age identity. Download it once after setting up the target (and again after changing it), and keep it offline, for example printed or on a USB stick in a safe.

Checking that backups work

The top of the page shows Last backup and Last restore test, each with its state, and the next planned times. Back up now and Test restore now start one at once. History lists every run, test and restore.

The weekly restore test takes the newest backup and restores it into throwaway places:

Administrators get a notification when a backup or a restore test fails.

Restoring files for one person

  1. Select Restore files.
  2. Choose the Backup (the date of the run).
  3. Under Files of, choose whose files or which library to restore from.
  4. Browse to a folder or file, or stay at All to restore everything.
  5. Under Into the files of, choose the person who receives the copy.
  6. Select Restore all, or Restore followed by the name you picked.

The files arrive in a new folder named "Restored" with the date and the source, in that person's files. Nothing already there is overwritten. Folders encrypted end to end are not in the restore: only their owner's keys can open them.

Restoring a whole server

You need the restore kit, your age identity, a new server with Hearth installed (the same or a newer version), an empty database and an empty file store. restore-server works with local storage (STORAGE=local).

  1. Install Hearth as in Installing, with the same settings as the old server, but do not create any users.

  2. Make a new, empty SYNC_LINEAGE_DIR folder. Never copy the old one. The commands below run in a one-off container of the Hearth image, so the kit and the identity must be inside it: mount the folder that holds them, for example with -v $PWD/restore:/restore:ro, and give the paths under /restore.

  3. Get the master key back from its copy:

    docker compose run --rm -T hearth backup restore-key \
      --kit kit.json --identity age-identity.txt --out /run/hearth/master.key
    

    --out must not exist yet. Write it where MASTER_KEY_FILE points (mount a writable folder for this step), then make it read only.

  4. Restore everything:

    docker compose run --rm -T hearth backup restore-server \
      --kit kit.json --vaultwarden-dir /data/vaultwarden
    

    It loads the newest run (or the one named with --run ID) into the database, the file store, Valkey and the Vaultwarden folder, migrates the database, and gives every storage a new sync epoch. --skip valkey leaves the sessions out; people then sign in again.

  5. Start Hearth and check /readyz.

restore-server refuses to run when a folder it writes into contains SYNC_LINEAGE_DIR. That folder must not match the restored database: Hearth uses the difference to tell every sync app that the server went back in time, and the apps then compare their folders instead of deleting files that the restored database does not know about.

Backing up by hand

If you do not use Hearth's backup, back up these yourself, ideally with the containers' data consistent with each other:

Leave out SYNC_LINEAGE_DIR. After restoring a database by hand, run this before Hearth serves anyone:

docker compose exec -T hearth /hearth sync new-epoch

Every sync app then lists its folders again rather than trusting what it knew.

Commands

Command What it does
hearth backup run a backup now
hearth backup test the restore test now
hearth backup status the state of backups and tests
hearth backup kit the restore kit, as JSON on standard output
hearth backup restore-key --kit F --identity F --out F [--run ID] the master key from its encrypted copy
hearth backup audit-anchors --kit F [--run ID] the audit log's daily anchors kept with a run, to compare with the database (Audit log)
hearth backup restore-server --kit F [--run ID] [--vaultwarden-dir D] [--skip PART,...] a whole backup into an empty server

Personal backups

In Settings, Backups, each person can copy their own files, or chosen folders, to storage of their own: S3 and compatible services, WebDAV, Nextcloud, SFTP, Google Drive or OneDrive.

You set two limits for everyone under Personal backups on the Administration, Backups page: Hours (the window personal backups run in, 01:00-07:00 by default) and Bandwidth (KiB/s). Back up now in a person's settings runs at once. A person is notified after three failed runs in a row.