Created
January 1, 2017 00:39
-
-
Save bpostlethwaite/308b0ec8b5d22585f31301dacca58f41 to your computer and use it in GitHub Desktop.
curlable backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z ${1} ]; then | |
echo "usage: backup [static|dynamic]" | |
exit 1 | |
fi | |
# see https://sipb.mit.edu/doc/safe-shell/ | |
set -euf -o pipefail | |
if [ $1 == "static" ]; then | |
source="/mnt" | |
target="/clone" | |
elif [ $1 == "dynamic" ]; then | |
source="" | |
target="/clone" | |
fi | |
if [ ! -d "$source/home" ]; then | |
echo "mount the PRIMARY drive onto $source/" | |
exit 1 | |
fi | |
if [ ! -d "$source/boot/EFI" ]; then | |
echo "mount the PRIMARY drive EFI partition to $source/boot" | |
exit 1 | |
fi | |
if [ ! -d "$target/home" ]; then | |
echo "mount the CLONE drive onto $target" | |
exit 1 | |
fi | |
if [ ! -d "$target/home/ben" ]; then | |
echo "mount the CLONE drive home partition onto $target/home" | |
exit 1 | |
fi | |
if [ ! -d "$target/boot/EFI" ]; then | |
echo "mount the CLONE drive EFI partition to $target/boot" | |
exit 1 | |
fi | |
declare -a exclude=( | |
'$source/.snapshots/*' | |
'$source/home/.snapshots/*' | |
'$source/dev/*' | |
'$source/proc/*' | |
'$source/sys/*' | |
'$source/tmp/*' | |
'$source/run/*' | |
'$source/mnt/*' | |
'$source/clone/*' | |
) | |
excluded="" | |
for path in "${exclude[@]}"; do | |
excluded="$excluded --exclude=$path" | |
done | |
echo sudo rsync -aAX --info=progress2 --delete $excluded $source/ $target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment