Backups & Snapshots
Back up SQLite by copying its files, or take automatic etcd snapshots on HA clusters.
Your cluster's entire state lives in its datastore, so backing it up is critical.
SQLite (single server)
Stop k3s and copy the /var/lib/rancher/k3s/server/db directory. Restore by putting the files back.
Embedded etcd (HA)
k3s takes automatic etcd snapshots on a schedule and can restore from them. Snapshots are saved under /var/lib/rancher/k3s/server/db/snapshots and can be shipped to S3-compatible storage.
Example
# Take an on-demand etcd snapshot
sudo k3s etcd-snapshot save --name pre-upgrade
# List snapshots
sudo k3s etcd-snapshot ls
# Restore a server from a snapshot (server stopped)
sudo k3s server \
--cluster-reset \
--cluster-reset-restore-path=/var/lib/rancher/k3s/server/db/snapshots/pre-upgradeWhen to use it
- An ops team schedules a nightly cron job to copy the k3s SQLite database file to an NFS share so the cluster can be restored after a server failure.
- A production k3s HA cluster uses automatic etcd snapshots saved to S3 so operators can restore to any point from the past 5 days.
- A developer takes a manual etcd snapshot before applying a large schema migration to provide a fast rollback path if the migration fails.
More examples
Back up the SQLite datastore
Stops k3s to get a consistent snapshot of the SQLite state file, copies it to a backup location, then restarts.
systemctl stop k3s
cp /var/lib/rancher/k3s/server/db/state.db \
/backup/k3s-state-$(date +%Y%m%d).db
systemctl start k3sTake an etcd snapshot manually
Creates a named etcd snapshot on an HA cluster and lists the snapshot directory to confirm the file was created.
k3s etcd-snapshot save --name pre-upgrade-$(date +%F)
ls /var/lib/rancher/k3s/server/db/snapshots/Configure automatic etcd snapshots
Configures k3s to take etcd snapshots every 6 hours, keeping the last 10, and storing them on a mounted backup drive.
# /etc/rancher/k3s/config.yaml (HA server)
etcd-snapshot-schedule-cron: '0 */6 * * *'
etcd-snapshot-retention: 10
etcd-snapshot-dir: /mnt/backup/etcd-snapshots
Discussion