fix(backup): SQLite hot backup instead of etcd snapshot

k3s runs in SQLite mode (no --cluster-init). Replace etcd-snapshot
with sqlite3 .backup for a WAL-aware hot copy of state.db.
Update restore guide to match. Cron installed under root crontab.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Bernd Worsch 2026-03-26 21:56:19 +00:00
parent ee6d7b149e
commit 2420915d30
2 changed files with 25 additions and 27 deletions

View file

@ -38,9 +38,9 @@ list_type() {
echo ""
}
list_type "etcd snapshots" "etcd-*.snap.age"
list_type "Helm values" "helm-values-*.tar.gz.age"
list_type "kubeconfig" "kubeconfig-*.yaml.age"
list_type "k3s state (SQLite)" "k3s-state-*.db.age"
list_type "Helm values" "helm-values-*.tar.gz.age"
list_type "kubeconfig" "kubeconfig-*.yaml.age"
echo "============================================"
echo ""
@ -50,14 +50,16 @@ echo ""
echo "Restore kubeconfig:"
echo " age -d -i ${AGE_KEY} ${BACKUP_DIR}/kubeconfig-<ts>.yaml.age > ~/.kube/config-hosteurope"
echo ""
echo "Restore etcd snapshot (WARNING: destroys current cluster state):"
echo " # 1. Decrypt the snapshot"
echo " age -d -i ${AGE_KEY} ${BACKUP_DIR}/etcd-<ts>.snap.age > /tmp/etcd-restore.snap"
echo " # 2. Copy to k3s snapshot directory"
echo " sudo cp /tmp/etcd-restore.snap /var/lib/rancher/k3s/server/db/snapshots/"
echo " # 3. Stop k3s and restore"
echo "Restore k3s state (SQLite) — WARNING: destroys current cluster state:"
echo " # 1. Decrypt the state db"
echo " age -d -i ${AGE_KEY} ${BACKUP_DIR}/k3s-state-<ts>.db.age > /tmp/k3s-restore.db"
echo " # 2. Stop k3s"
echo " sudo systemctl stop k3s"
echo " sudo k3s server --cluster-reset --cluster-reset-restore-path=/var/lib/rancher/k3s/server/db/snapshots/etcd-restore.snap"
echo " # 3. Replace the state db"
echo " sudo cp /var/lib/rancher/k3s/server/db/state.db /var/lib/rancher/k3s/server/db/state.db.bak"
echo " sudo cp /tmp/k3s-restore.db /var/lib/rancher/k3s/server/db/state.db"
echo " sudo rm -f /var/lib/rancher/k3s/server/db/state.db-shm /var/lib/rancher/k3s/server/db/state.db-wal"
echo " # 4. Start k3s"
echo " sudo systemctl start k3s"
echo ""
echo "Restore Helm values (for re-running helm upgrade after cluster restore):"