Skip to content

Backups

Backups come in two halves. The cluster backs its data up to the NAS, and the NAS protects its own datasets (including the cluster's backups) with ZFS snapshots and an encrypted off-site copy in Backblaze B2.

What Tool Destination Schedule Retention
App PVCs Kopiur (Kopia) NFS repo on the NAS, /mnt/vault/Backups/Cluster/main/kopiur Hourly (minute hashed per app) 3 latest, 24 hourly, 7 daily, 4 weekly
PostgreSQL (WAL + base) CNPG Barman Cloud plugin Garage S3, s3://postgresql/<app>/ Continuous WAL, daily base 14 days
PostgreSQL (dumps) postgres-backup-local NAS, /mnt/vault/Backups/Database Daily 7 daily, 4 weekly, 1 monthly
MariaDB (binlogs + base) mariadb-operator PointInTimeRecovery and PhysicalBackup Garage S3, s3://mariadb/<app>/v<timeline>/ Continuous binlogs, daily base 14 days (base backups)
MariaDB (dumps) mariadb-operator Backup NAS, /mnt/vault/Backups/Database Daily 30 days
Kopia repository (off-site copy) Kopiur RepositoryReplication Backblaze B2, b2://bykaj-backups/cluster/main/ Daily at 01:30 Exact mirror of the NAS repository
NAS datasets (local versions) ZFS periodic snapshots Same pool (vault) Hourly to monthly, per dataset See ZFS snapshots
NAS datasets (off-site copy) TrueCloud Backup (restic) Backblaze B2, b2://bykaj-backups/nas/<dataset> Daily or weekly, per dataset See TrueCloud Backup
Documents TrueNAS Cloud Sync (WebDAV) Filen, through the 08-filen-cli stack, and a shared Seafile library Hourly Mirror
Macs Time Machine over SMB NAS, /mnt/vault/TimeMachine Hourly (macOS) Time Machine thinning, see Time Machine

The cluster's data lands on the NAS first. From there the Kopia repository is copied off-site by Kopiur itself (see Off-site copy), and everything else that matters goes off-site through TrueCloud Backup (see NAS backups).

Cluster backups

The cluster backs up app volumes with Kopiur and databases with CNPG. Both land on the NAS, and the Kopia repository is mirrored to B2 from inside the cluster.

PVC backups with Kopiur

Apps opt in by adding the kopiur component to their Flux Kustomization (see Components). The component creates, per app:

  • a SnapshotPolicy: what to back up (the app's PVC), how (zstd compression, CSI snapshot via csi-ceph-blockpool first), where (the nas ClusterRepository) and retention
  • a SnapshotSchedule: cron: H * * * *, hourly at a per-app hashed minute
  • the app's PVC itself, with spec.dataSourceRef pointing at a Restore
  • the Restore, which acts as a volume populator

The mover runs as UID/GID 4000 by default and keeps a persistent cache on openebs-hostpath, as large as the app's volume (KOPIUR_CAPACITY, 5Gi by default, 1Gi for many apps). Hostpath volumes don't enforce their size, so the ClusterRepository caps Kopia's cache budgets instead: 512 MiB for content and 1 GiB for metadata, which Kopia applies twice (also to its index-blob cache), about 2.5 GiB per cache on the node's disk. Kopia's own default is 5000 MiB per budget. The budgets are fixed on purpose: budgets as a percentage of capacity would give the largest caches (Plex, 120Gi) tens of GiB, and growing a cache PVC is not possible on openebs-hostpath.

Changing the mover UID

Changing KOPIUR_MOVER_UID for an existing app breaks its backups until the kopiur-cache-<app> PVC is deleted. The old cache is owned by the previous UID.

Off-site copy

The Kopia repository on the NAS (/mnt/vault/Backups/Cluster/main/kopiur) is replicated to Backblaze B2 every night. This follows the 3-2-1 rule: the live data on Ceph, the Kopia repository on the NAS, and a copy outside the house.

Kopiur runs the replication from inside the cluster, as a RepositoryReplication named nas-offsite (kubernetes/apps/system/kopiur/repository/repositoryreplication.yaml):

Setting Value
Source ClusterRepository nas
Destination B2 bucket bykaj-backups, prefix cluster/main/
Schedule 30 1 * * *, daily at 01:30
Sync deleteExtra: true (an exact mirror, so blobs pruned on the NAS are also removed from B2), 8 parallel transfers
Credentials Secret kopiur-replication-secret

Because it is an exact mirror, the B2 copy has the same snapshots and retention as the NAS. It is also a complete Kopia repository, so any Kopia client with the B2 credentials and the repository password can open it directly.

Set suspend: true on the RepositoryReplication to pause it, for example while repairing the NAS repository, so a damaged repository isn't mirrored over the good off-site copy.

Restoring from B2

The normal deploy-or-restore flow reads from the NAS. If the NAS copy is lost, restore the repository from B2 to the same NFS path first, then let Flux and Kopiur restore the apps as usual.

The B2 copy lags the NAS by up to a day, so a restore from B2 loses at most the last day of changes.

Deploy-or-restore

Bootstrap restores no application data itself. Restores happen declaratively once Flux takes over:

  1. Flux applies an app on a fresh cluster. Its PVC has spec.dataSourceRef pointing at a Kopiur Restore with target.populator: {}.
  2. Kopiur resolves the latest snapshot for the app's SnapshotPolicy and runs a restore mover Job into the new volume. The PVC stays unbound meanwhile, so the app's pod stays Pending. No ordering logic is needed anywhere.
  3. When the restore finishes, the PVC binds and the app starts with its data.

The Restores use onMissingSnapshot: Continue, so an app with no snapshot yet (a brand-new app, or a deliberate fresh start) comes up with an empty volume instead of failing. The same manifests handle both first deploy and disaster recovery.

Each Restore pins the snapshot it resolved on first reconciliation and never silently retargets, even if a schedule fires mid-restore.

Manual backups

Take a one-off snapshot of an app's volume, for example before a risky change:

just k8s pvc-backup <namespace> <app>

The recipe creates a Snapshot named <app>-manual-<suffix> for the app's SnapshotPolicy; follow it with kubectl -n <namespace> get snapshot. It falls under the policy's retention like the scheduled ones.

Restores

To bring back some files, or roll an app's volume back to a snapshot, see Restoring a Volume.

Database backups

See PostgreSQL → Backups and MariaDB → Backups. A manual base backup is one recipe away; it finds out whether the app has a CNPG cluster or a MariaDB:

just k8s db-backup <namespace> <app>

Upgrade safety

The tuppr TalosUpgrade and KubernetesUpgrade plans wait until no Kopiur Snapshot is Running and no Restore is resolving or restoring, and until Ceph reports HEALTH_OK. See Upgrades.

NAS backups

The NAS has one ZFS pool, vault, with one dataset per share. Each dataset gets a protection level that fits how replaceable its data is:

Dataset Contents ZFS snapshots Off-site (TrueCloud)
Applications Data of the Compose stacks (Garage, Bootimus) Hourly + daily + weekly Daily, keep 14 (without zot and filen-cli)
Archive Paperless documents Daily + monthly Daily, keep 30
Backups Client and server backups, Postgres dumps Daily Daily, keep 14 (without Cluster and Excluded)
Downloads, Software, Transfer, Users Recreatable or transient data None None
Media Books, music and video libraries Daily + monthly Weekly, keep 12 (only Books and Music)
Photos Photo albums and the Immich library Daily + monthly Daily, keep 30
TimeMachine Time Machine backups of the Macs On every backup (share auto-snapshot), kept 7 days None

ZFS snapshots

Periodic snapshot tasks give every protected dataset local version history: quick to take, cheap in space, and the fastest way to undo a deleted or overwritten file. They live on the same pool, so they don't protect against losing the pool itself. That is what the off-site copy is for.

All tasks are recursive and use the naming schema auto-%Y-%m-%d_%H-%M.

Dataset Schedule Kept for Allow empty
Applications Hourly, on the hour 24 hours No
Applications Daily at 00:00 14 days Yes
Applications Weekly, Sunday at 00:00 8 weeks Yes
Archive Daily at 01:00 30 days Yes
Archive Monthly, 1st at 01:30 12 months Yes
Backups Daily at 03:00 7 days No
Media Daily at 05:00 2 weeks Yes
Media Monthly, 1st at 05:30 6 months Yes
Photos Daily at 06:00 30 days Yes
Photos Monthly, 1st at 06:30 12 months Yes

Snapshots of running apps (Garage, Bootimus) are crash-consistent. That is enough for Garage's immutable data blocks and for embedded metadata stores that recover like after a power loss.

TrueCloud Backup

TrueCloud Backup is TrueNAS's built-in wrapper around restic. Each task backs one dataset up to its own restic repository in the bykaj-backups B2 bucket, under nas/<dataset>. restic deduplicates, versions and encrypts everything on the NAS before upload, so B2 only ever sees encrypted chunks.

Requires the TrueCloud patch

Out of the box, TrueCloud Backup only supports Storj as a destination. Backing up to B2 is only possible with truenas-truecloud-patch, which adds Backblaze B2 and S3-compatible providers, and snapshots of datasets with child datasets. It installs as a PREINIT boot hook that re-applies the patch at every boot, so it survives TrueNAS updates. Without it, the tasks below can't run.

Task Source B2 folder Schedule Keep last Exclude
Applications Daily /mnt/vault/Applications /nas/applications Daily at 06:30 14 **/zot, **/filen-cli
Archive Daily /mnt/vault/Archive /nas/archive Daily at 02:00 30
Backups Daily /mnt/vault/Backups /nas/backups Daily at 04:30 14 **/Cluster, **/Excluded
Media Weekly /mnt/vault/Media /nas/media Weekly, Sunday at 04:00 12 **/Series, **/Movies, **/Documentaries
Photos Daily /mnt/vault/Photos /nas/photos Daily at 03:30 30

All tasks have Use Snapshot enabled: TrueNAS takes a temporary ZFS snapshot when the task starts and backs that up, so restic reads a frozen, point-in-time view instead of files that running apps or clients are still writing. Tasks are staggered so they don't compete for upload bandwidth. Keep last counts backup runs, so a daily task with 30 keeps about a month and the weekly Media task with 12 keeps about three months.

Why some data is excluded:

  • Backups/Cluster holds the Kopia repository. It already has its own versioning and its own off-site mirror (see Off-site copy). Wrapping Kopia's encrypted, chunked blobs in restic would only store them a second time.
  • Backups/Excluded is the place for client data that deliberately stays local.
  • Applications/zot is the Zot pull-through cache. It refills itself from the upstream registries.
  • Applications/filen-cli holds the Filen CLI's managed rclone and its WebDAV cache. The CLI downloads rclone again when it is missing, the cache only holds copies of documents that are already backed up, and the auth config comes from 1Password.
  • Media/Series, Movies, Documentaries are large and recreatable. Only Books and Music go off-site.

Everything else in Backups does go off-site. Clients drop backups there without keeping a copy of their own, so for them the NAS is the only copy. It also holds the daily Postgres dumps (Backups/Database) and cluster app backups (Backups/Apps). Garage's data in Applications includes the CNPG WAL archives and base backups, the MariaDB base backups and binlogs, and the Karakeep, Windshift, OpenCloud and Seafile buckets, so those go off-site through the Applications task. Kopiur doesn't cover them.

Exclude patterns with Use Snapshot

With Use Snapshot enabled, the Use Absolute Paths option is disabled, and restic reads from the snapshot rather than from /mnt/vault/<dataset>. Root-anchored patterns like /Series then match nothing, and the task silently backs up the whole dataset. Use **/Series instead. It matches a Series file or folder at any depth, so don't reuse an excluded name for data deeper in the dataset that must be backed up.

The task password is the restic repository password. TrueNAS encrypts the repository with it, so without it the B2 copy can't be read or restored.

Time Machine

The Macs back up to the NAS with Time Machine over SMB. They use their own dataset and share, kept out of Backups on purpose: Time Machine keeps rewriting the 8 MiB band files inside its sparsebundles, and under Backups that churn would bloat the daily snapshots and be uploaded to B2 every night.

Setting Value
Dataset vault/TimeMachine, SMB preset, recordsize=1M, lz4, sync=standard
Quota 3 TiB (ZFS quota on the dataset)
Owner A personal NAS user; the ACL grants only that user, its group and builtin_administrators (no builtin_users, so service accounts have no access)
Share TimeMachine, purpose Time Machine Share, advertised over mDNS
Auto snapshot On: the NAS takes a ZFS snapshot (aapltm-<epoch>) each time a Mac starts a backup, and deletes those older than 7 days
Auto dataset creation Off: all Macs share the dataset, one sparsebundle per Mac
Server-side Time Machine quota 0 (limits are set on the Macs)

Each Mac logs in as the dataset's owner and backs up all of its macOS users into a single sparsebundle. The space is split with the Disk usage limit in each Mac's Time Machine settings, at about twice the Mac's disk size:

Mac Disk Disk usage limit
MacBook M4 Pro 1 TB 2 TB
Mac mini M6 256 GB 512 GB

Without these limits, one Mac could fill the whole 3 TiB quota. sync stays at standard: macOS sends full-fsync requests, and ignoring them risks a corrupted sparsebundle after a power cut, which makes Time Machine start over.

To add a Mac, pick TimeMachine under System Settings → General → Time Machine → Add Backup Disk. If the share doesn't appear (mDNS doesn't cross VLANs), add it by hand (-p prompts for the password):

sudo tmutil setdestination -a -p smb://<user>@nas.internal/TimeMachine

Time Machine versions the backups itself, so the dataset has no periodic snapshot task and no TrueCloud task. The auto snapshots are there to restore a sparsebundle when Time Machine reports a failed verification. Samba's vfs_tmprotect module takes them and prunes them itself: each time it takes a new snapshot, it deletes the ones older than 7 days, but always keeps at least 3. So their space levels off, at about 160 GiB with hourly backups from two Macs, instead of growing. List them with zfs list -t snapshot -o name,creation,used vault/TimeMachine. All Macs share the dataset, so never zfs rollback it: that reverts every Mac's backups, and rolling back past the latest snapshot needs -r, which destroys all newer snapshots. Restore only the affected sparsebundle instead, with that Mac's backups paused:

cd /mnt/vault/TimeMachine
mv "<Mac>.sparsebundle" "<Mac>.sparsebundle.broken"
cp -a ".zfs/snapshot/<snapshot>/<Mac>.sparsebundle" .

Delete the .broken copy once Time Machine verifies the backup again.

Document sync

Two TrueNAS Cloud Sync tasks push /mnt/vault/Archive/media/documents/originals over WebDAV every hour, in sync mode: one to the /Archief folder of the Filen drive, one to a shared Archief library in Seafile. Both are convenient, readable mirrors of the original documents rather than backups: deletions on the NAS are mirrored too. The versioned copy is the Archive TrueCloud task.

Destination WebDAV URL Credential (vendor Other) Remote folder
Filen https://webdav.bykaj.io FILEN_WEBDAV_USERNAME and FILEN_WEBDAV_PASSWORD from the filen-cli 1Password item /Archief
Seafile https://files.bykaj.app/seafdav The library owner's contact email and the WebDAV password set under Settings in Seafile /Archief-<id>, the Archief library
  • Filen has no WebDAV endpoint of its own; the task talks to the WebDAV server of the 08-filen-cli stack, which logs in to the Filen account. If that stack is down, the task fails until it is back.
  • Seafile serves WebDAV itself (SeafDAV), and the NAS reaches it directly on the envoy-external LoadBalancer, so there is no upload size limit. The library is owned by one account, whose quota the files count toward, and is shared with the other users read-only: sync mode deletes anything in it that isn't on the NAS, files other users add included. SeafDAV always shows a library as its name plus - and the first six characters of its ID, so the remote folder only changes if the library is recreated.

Restoring NAS data

  • Recent mistakes: restore the file or dataset from a ZFS snapshot (Datasets → Snapshots in the TrueNAS UI, or the dataset's .zfs/snapshot/ directory).
  • Lost pool or older versions: use Restore on the TrueCloud Backup task to pick a backup run and restore it, whole or in part, to a path on the NAS.
  • Mac files: restore from Time Machine on the Mac (Finder, or Migration Assistant for a whole machine). If a sparsebundle is damaged, copy only that Mac's sparsebundle back from an auto snapshot (see Time Machine); don't roll back the shared dataset.

Nightly timeline

Time Job
Every hour Applications snapshot, Kopiur PVC backups, document sync to Filen and Seafile
00:00 Applications daily (and Sunday weekly) snapshot
01:00 Archive snapshot
01:30 Kopia repository replication to B2
02:00 Archive TrueCloud backup
03:00 Backups snapshot
03:30 Photos TrueCloud backup
04:00 Media TrueCloud backup (Sundays)
04:30 Backups TrueCloud backup
05:00 Media snapshot
06:00 Photos snapshot
06:30 Applications TrueCloud backup

Monthly snapshots run half an hour after each dataset's daily one, on the 1st.