Skip to content
Mementropy
RecipesHomelab recipesReference

Scheduling homelab backups with a systemd timer

Nightly datastore, database and volume-file backups to the NAS, with pruning.

By Ryan Hammang

Status: Dell K3s state not yet covered.

Running the whole backup on a schedule, including file volumes and every database.

  • The backup script and Restic repository from the K3s backup recipe
  1. Give the script an all mode that runs, in order:

    • the K3s datastore backup
    • pg_dump -Fc for 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
  2. Archive volumes from distroless images through the host path, not kubectl exec tar:

Terminal window
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
  1. 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.service
Wants=network-online.target
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/sbin/backup-x1.sh all
Nice=10
IOSchedulingClass=best-effort
IOSchedulingPriority=7
# /etc/systemd/system/k3s-x1-backup.timer
[Timer]
OnCalendar=*-*-* 03:15:00 UTC
Persistent=true
RandomizedDelaySec=5m
[Install]
WantedBy=timers.target
Terminal window
sudo systemctl daemon-reload
sudo systemctl enable --now k3s-x1-backup.timer
  1. Record each run’s result where your monitoring can read it, for example a receipt ConfigMap with timestamps and table counts.
  • systemctl list-timers shows the next run.
  • restic snapshots --tag pvc-blobs shows volume snapshots.
  • The receipt is less than 30 hours old.
  • 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.