This commit is contained in:
2025-12-03 23:28:59 +01:00
parent 2fd893e18d
commit c2f5d4a302

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Define backup directory on your local machine
BACKUP_DIR="/path/to/your/backups"
WEEKLY_DIR="$BACKUP_DIR/weekly"
# Run the backup script
ssh server /root/backup/script.sh
scp server:/root/backup/backup_$(date +"%Y%m%d").tar "$BACKUP_DIR"
ssh server rm /root/backup/backup_$(date +"%Y%m%d").tar
# Keep only the last 7 daily backups
find "$BACKUP_DIR" -maxdepth 1 -name "backup_*.tar" -type f -mtime +6 -exec rm {} \;
# Weekly backup: Every Sunday, move the daily backup to a weekly folder
if [ "$(date +%u)" -eq 7 ]; then
mkdir -p "$WEEKLY_DIR"
cp "$BACKUP_DIR/backup_$(date +"%Y%m%d").tar" "$WEEKLY_DIR/weekly_$(date +"%Y%m%d").tar"
# Enforce 100 GB limit for weekly backups
while true; do
TOTAL_SIZE=$(du -s "$WEEKLY_DIR" | awk '{print $1}')
if [ "$TOTAL_SIZE" -le 102400 ]; then # 100 GB in KB
break
fi
# Find and remove the oldest weekly backup
OLDEST_FILE=$(ls -t "$WEEKLY_DIR" | tail -1)
if [ -n "$OLDEST_FILE" ]; then
rm "$WEEKLY_DIR/$OLDEST_FILE"
fi
done
fi