Files
kube-cluster/backup.md
2026-03-31 15:30:40 +00:00

1.2 KiB
Raw Permalink Blame History

3 Create the backup script on the master node

Create /usr/local/bin/backup-storage.sh:

sudo nano /usr/local/bin/backup-storage.sh

#!/bin/bash
set -e

SRC="/storage/"
DEST="debian@192.168.1.30:/backup/master-storage/"
SSH_KEY="/home/adrien/.ssh/id_backup"
LOG="/var/log/storage-backup.log"

echo "=== Backup started at $(date) ===" >> $LOG

rsync -aHAX --numeric-ids --delete \
  --link-dest=/backup/master-storage/latest \
  -e "ssh -i $SSH_KEY" \
  "$SRC" "$DEST/$(date +%F)/" >> $LOG 2>&1

ssh -i $SSH_KEY debian@192.168.1.30 \
  "ln -sfn /backup/master-storage/$(date +%F) /backup/master-storage/latest"

echo "=== Backup finished at $(date) ===" >> $LOG

What this gives you

Daily folders (2025-01-14/)

A latest symlink

Efficient incremental backups

Clean deletions mirrored (--delete)

sudo crontab -e

0 2 * * * /usr/local/bin/backup-storage.sh

5 Verify backups on vm-nfs

ls -lah /backup/master-storage

You should see:

2025-01-14/ latest -> 2025-01-14

6 Restore (very important)

To restore everything:

rsync -aHAX /backup/master-storage/latest/ /storage/

To restore a single folder:

rsync -aHAX /backup/master-storage/2025-01-10/prometheus/ /storage/prometheus/