clonedisk (1226B)
1 #!/usr/bin/env bash 2 3 # Disc backup/clone script 4 # Requires rsync 3 5 6 # Ask for the administrator password upfront 7 sudo -v 8 9 if [ $# -ne 2 ]; then 10 echo "Usage: clonedisk [source] [destination]" 11 exit 1 12 else 13 SRC=$1 14 DST=$2 15 fi 16 17 EXCLUDE="clonedisk-ignore" 18 19 PROG=$0 20 21 if [ ! -r "$SRC" ]; then 22 logger -t $PROG "Source $SRC not readable - Cannot start the sync process" 23 exit; 24 fi 25 26 if [ ! -w "$DST" ]; then 27 logger -t $PROG "Destination $DST not writeable - Cannot start the sync process" 28 exit; 29 fi 30 31 logger -t $PROG "Start rsync" 32 33 sudo /usr/local/bin/rsync --acls \ 34 --archive \ 35 --delete \ 36 --delete-excluded \ 37 --exclude-from=$EXCLUDE \ 38 --hard-links \ 39 --one-file-system \ 40 --sparse \ 41 --verbose \ 42 --xattrs \ 43 "$SRC" "$DST" 44 45 logger -t $PROG "End rsync" 46 47 echo -n "Make the backup disk bootable? [Y/n]: " 48 read -nq shouldboot 49 50 if [ $shouldboot == "y" ]; then 51 # Make the backup bootable 52 sudo bless -folder "$DST"/System/Library/CoreServices 53 fi 54 55 exit 0