66 lines
1.2 KiB
Markdown
66 lines
1.2 KiB
Markdown
|
||
## 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/ |