|
@@ -1,22 +1,53 @@
|
|
|
#!/bin/bash
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
-DISK=/Volumes/Server
|
|
|
|
|
-SERVER=cnew
|
|
|
|
|
|
|
+SERVER=${1:-"cnew"}
|
|
|
|
|
+DISK=${2:-"/Volumes/Server"}
|
|
|
|
|
+BWLIMIT=${3:-"0"}
|
|
|
|
|
+ONLY_RASPI=${4:-"N"}
|
|
|
|
|
+
|
|
|
|
|
+echo "Backing up server $SERVER to disk $DISK."
|
|
|
|
|
+
|
|
|
|
|
+if [[ "$BWLIMIT" != "0" ]]; then
|
|
|
|
|
+ echo "I/O bandwidth limit (rsync --bwlimit) is $BWLIMIT"
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
|
|
+if [[ "$ONLY_RASPI" == "Y" ]]; then
|
|
|
|
|
+ echo "Skipping main backup. Only backing up raspi"
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
|
|
+read -n 1 -p "Press Y to continue: " userinput
|
|
|
|
|
+echo
|
|
|
|
|
+if [[ "$userinput" != "Y" ]]; then
|
|
|
|
|
+ echo "Abort."
|
|
|
|
|
+ exit
|
|
|
|
|
+else
|
|
|
|
|
+ echo "Backing up."
|
|
|
|
|
+fi
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
# Basic snapshot-style rsync backup script
|
|
# Basic snapshot-style rsync backup script
|
|
|
date=`date "+%Y-%m"`
|
|
date=`date "+%Y-%m"`
|
|
|
|
|
|
|
|
# Run rsync to create snapshot
|
|
# Run rsync to create snapshot
|
|
|
# exclude backups on the remote to prevent filling with hardlinks
|
|
# 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
|
|
|
|
|
|
|
+if [[ "$ONLY_RASPI" != "Y" ]]; then
|
|
|
|
|
+ rsync -aPhRz \
|
|
|
|
|
+ --bwlimit=$BWLIMIT \
|
|
|
|
|
+ --exclude "*-backup*/*" --exclude="*cache*" --rsync-path "sudo rsync" \
|
|
|
|
|
+ --link-dest=$DISK/last $SERVER:/etc :/home :/var :/root $DISK/$date
|
|
|
|
|
+else
|
|
|
|
|
+ echo "Skipped main backup"
|
|
|
|
|
+fi
|
|
|
|
|
|
|
|
# copy lastest backups by following symlinks
|
|
# copy lastest backups by following symlinks
|
|
|
# need to explicitly include each level of directories before adding a global
|
|
# need to explicitly include each level of directories before adding a global
|
|
|
# */last pattern
|
|
# */last pattern
|
|
|
rsync -aPhRzLK \
|
|
rsync -aPhRzLK \
|
|
|
- --include "var/" --include "*-backups/" --include "home/raspi-backup/" \
|
|
|
|
|
|
|
+ --bwlimit=$BWLIMIT \
|
|
|
|
|
+ --include "var/" --include "*-backups/" \
|
|
|
|
|
+ --exclude ".npm/*" --exclude "*cache*/*" \
|
|
|
|
|
+ --include "home/" --include "home/raspi-backup/" \
|
|
|
--include "*-backup*/last" --include "*-backup*/last/**" --exclude="*" --rsync-path "sudo rsync" \
|
|
--include "*-backup*/last" --include "*-backup*/last/**" --exclude="*" --rsync-path "sudo rsync" \
|
|
|
--link-dest=$DISK/last $SERVER:/home/raspi-backup :/var $DISK/$date
|
|
--link-dest=$DISK/last $SERVER:/home/raspi-backup :/var $DISK/$date
|
|
|
|
|
|