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:
BACKUP_LOCAL_ROOTS: folders on the server a backup may be written to, comma-separated. Empty offers no local folder.BACKUP_VAULTWARDEN_DIR: the Vaultwarden data folder, mounted read only, so the password vaults are in the backup too (Passwords).BACKUP_THREADS: processors restic may use (2 by default, 1 to 16).BACKUP_TEST_DATABASE_URL: an empty database for the weekly restore test. Empty: Hearth makes one beside the main database and drops it afterwards, which needs theCREATEDBright.JOBS_TIME_ZONE: the time zone the schedule is read in (UTC by default).
See the configuration reference for every value.
Where the backup goes
- Go to Administration, Backups.
- 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.
- Folder on this server: a folder inside one of
- 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:
- Every night: the switch and the time the backup starts.
- Keep: how many daily, weekly, monthly and yearly backups to keep (7, 4, 12 and 3 by default). The newest backup of each day, week, month and year is kept; older ones are forgotten, and their space is freed once a week.
- Weekly restore test: the switch, the day and the hour.
- Upload limit (KiB/s, 0 none): a ceiling on the backup's upload speed.
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 database: every table, from one consistent snapshot, with each table's row count and checksum.
- The file store: files, versions, trash, libraries and Office fonts. Thumbnails and unfinished uploads are left out; Hearth makes them again.
- Valkey: the sign-in sessions, so people stay signed in after a restore.
- Vaultwarden's folder, when
BACKUP_VAULTWARDEN_DIRis set, copied consistently while it runs.
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:
On a computer you trust, make an age key pair:
age-keygen -o age-identity.txtThe file holds the private identity. The line starting
age1is the public key.Paste the public key into Master key copy: age public key and select Save.
Keep
age-identity.txtoffline, 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:
- the database into a database of its own, with every table's rows and checksums compared against what was backed up, and the at-rest keys opened;
- up to 200 files, whose contents are checked against the hashes the database holds;
- the other parts, read through;
- a twelfth of the repository's data, read and checked, so the whole repository is read about every three months.
Administrators get a notification when a backup or a restore test fails.
Restoring files for one person
- Select Restore files.
- Choose the Backup (the date of the run).
- Under Files of, choose whose files or which library to restore from.
- Browse to a folder or file, or stay at All to restore everything.
- Under Into the files of, choose the person who receives the copy.
- 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).
Install Hearth as in Installing, with the same settings as the old server, but do not create any users.
Make a new, empty
SYNC_LINEAGE_DIRfolder. 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.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--outmust not exist yet. Write it whereMASTER_KEY_FILEpoints (mount a writable folder for this step), then make it read only.Restore everything:
docker compose run --rm -T hearth backup restore-server \ --kit kit.json --vaultwarden-dir /data/vaultwardenIt 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 valkeyleaves the sessions out; people then sign in again.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:
- a dump of the database:
pg_dump -Fcof the Hearth database; - the file store (
STORAGE_DIR, or the S3 bucket); - the Valkey data folder, if you want sessions kept;
- Vaultwarden's data folder, if you run Passwords;
- the
.envfile and the secrets, with the master key kept apart from the rest.
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.
- The copies are plain files laid out as in Hearth. Nothing is restored through Hearth; the person browses their own target.
- A person may encrypt the copies to their own age public key. Hearth holds nothing that can open them.
- Only the person's own files are copied, never shares, libraries or external storage. Folders encrypted end to end are left out.
- Runs copy only what changed since the last run.
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.