Scheduling homelab backups with a systemd timer
Nightly datastore, database and volume-file backups to the NAS, with pruning.
Status: Dell K3s state not yet covered.
What it’s for
Section titled “What it’s for”Running the whole backup on a schedule, including file volumes and every database.
What you need
Section titled “What you need”- The backup script and Restic repository from the K3s backup recipe
-
Give the script an
allmode that runs, in order:- the K3s datastore backup
pg_dump -Fcfor each database, with a scratch-restore table count- archives of file volumes (Git repositories, LFS, attachments, object storage)
restic forget --keep-daily 14 --keep-weekly 8 --prune
-
Archive volumes from distroless images through the host path, not
kubectl exec tar:
PV=$(kubectl get pvc -n kaneo data-silo-0 -o jsonpath='{.spec.volumeName}')P=$(kubectl get pv "$PV" -o jsonpath='{.spec.local.path}')tar -C "$P" -cf - . | restic -r <repo> backup --stdin --stdin-filename silo.tar --tag pvc-blobs- Add a service and a timer:
# /etc/systemd/system/k3s-x1-backup.service (from k3s/scripts/systemd/ in the repo)[Unit]After=network-online.target k3s.serviceWants=network-online.target
[Service]Type=oneshotUser=rootExecStart=/usr/local/sbin/backup-x1.sh allNice=10IOSchedulingClass=best-effortIOSchedulingPriority=7
# /etc/systemd/system/k3s-x1-backup.timer[Timer]OnCalendar=*-*-* 03:15:00 UTCPersistent=trueRandomizedDelaySec=5m
[Install]WantedBy=timers.targetsudo systemctl daemon-reloadsudo systemctl enable --now k3s-x1-backup.timer- Record each run’s result where your monitoring can read it, for example a receipt ConfigMap with timestamps and table counts.
Check it worked
Section titled “Check it worked”systemctl list-timersshows the next run.restic snapshots --tag pvc-blobsshows volume snapshots.- The receipt is less than 30 hours old.
Traps seen
Section titled “Traps seen”- Datastore and database dumps alone would restore Gitea’s metadata with no repositories.
- Minimal images don’t have
tar. - Add each new database (here LiteLLM and Hindsight) to both the script and the auditor.
The Dell cluster’s K3s state isn’t covered yet.
Where this came from
Section titled “Where this came from”- Reviewing phases 1 to 3 (2026-10-20)
- Moving LiteLLM and its database to K3s (2026-10-21)