Quellcode durchsuchen

Add server backup script

Kevin Heinicke vor 1 Jahr
Ursprung
Commit
8f6f223b07
1 geänderte Dateien mit 27 neuen und 0 gelöschten Zeilen
  1. 27 0
      scripts/backup_server_to_disk.sh

+ 27 - 0
scripts/backup_server_to_disk.sh

@@ -0,0 +1,27 @@
+#!/bin/bash
+
+DISK=/Volumes/Server
+SERVER=cnew
+
+# Basic snapshot-style rsync backup script
+date=`date "+%Y-%m"`
+
+# Run rsync to create snapshot
+# exclude backups on the remote to prevent filling with hardlinks
+rsync -aPhRz \
+    --exclude "*-backup*/*" --exclude="*cache*" --rsync-path "sudo rsync" \
+    --link-dest=$DISK/last $SERVER:/etc :/home :/var :/root $DISK/$date
+
+# copy lastest backups by following symlinks
+# need to explicitly include each level of directories before adding a global
+# */last pattern
+rsync -aPhRzLK \
+    --include "var/" --include "*-backups/" --include "home/raspi-backup/" \
+    --include "*-backup*/last" --include "*-backup*/last/**" --exclude="*" --rsync-path "sudo rsync" \
+    --link-dest=$DISK/last $SERVER:/home/raspi-backup :/var $DISK/$date
+
+# Remove symlink to previous snapshot
+rm -f $DISK/last
+
+# Create new symlink to latest snapshot for the next backup to hardlink
+ln -s $DISK/$date $DISK/last