Skip to content

Instantly share code, notes, and snippets.

@djch
Created May 31, 2016 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djch/630b67107d00a3f8a9daf54559aa5014 to your computer and use it in GitHub Desktop.
Save djch/630b67107d00a3f8a9daf54559aa5014 to your computer and use it in GitHub Desktop.
Rsync 3 script for migrating one Time Machine drive to another
#!/usr/bin/env bash
# Inspired by: http://nicolasgallagher.com/mac-osx-bootable-backup-drive-with-rsync/
# --acls update the destination ACLs to be the same as the source ACLs
# --archive turn on archive mode (recursive copy + retain attributes)
# --delete delete any files that have been deleted locally
# --delete-excluded delete any files (on DST) that are part of the list of excluded files
# --exclude-from reference a list of files to exclude
# --hard-links preserve hard-links
# --one-file-system don't cross device boundaries (ignore mounted volumes)
# --sparse handle sparse files efficiently
# --verbose increase verbosity
# --xattrs update the remote extended attributes to be the same as the local ones
# Ask for the administrator password upfront
sudo -v
# IMPORTANT: Make sure you update the `DST` variable to match the name of the
# destination backup drive
SRC="/Volumes/Backup/"
DST="/Volumes/Time Machine/"
PROG=$0
if [ ! -r "$SRC" ]; then
logger -t $PROG "Source $SRC not readable - Cannot start the sync process"
exit;
fi
if [ ! -w "$DST" ]; then
logger -t $PROG "Destination $DST not writeable - Cannot start the sync process"
exit;
fi
logger -t $PROG "Start rsync"
sudo /usr/local/Cellar/rsync/3.1.2/bin/rsync --acls \
--archive \
--delete \
--hard-links \
--sparse \
--verbose \
--xattrs \
--progress \
"$SRC" "$DST"
logger -t $PROG "End rsync"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment