Skip to content

Commit

Permalink
bin: Create a new bin including a backup script
Browse files Browse the repository at this point in the history
The dotfiles bin is added to the PATH and includes a simple
rsync-powered drive backup script. I use it to backup my MacBook Pro's
SSD drive to an external HDD, but the destination drive name can be
edited to match the name of any external drive.
  • Loading branch information
necolas committed Apr 16, 2012
1 parent c23444e commit 98c00a8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bash/exports
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export HISTCONTROL=ignoredups
export HISTIGNORE="ls:ls *:cd:cd -:pwd;exit:date:* --help"

# if these bins exist, then add them to the PATH
[ -d "/usr/bin" ] && PATH="$PATH:/usr/bin";
[ -d "/usr/bin" ] && PATH="$PATH:/usr/bin";
[ -d "$HOME/bin" ] && PATH="$PATH:$HOME/bin";
[ -d "$HOME/.dotfiles/bin" ] && PATH="$PATH:$HOME/.dotfiles/bin";
# add to beginning of PATH so that it always take precedence over /usr/bin
[ -d "/usr/local/bin" ] && PATH="/usr/local/bin:$PATH";
# if the current user has a ~/bin, then add it to the PATH
[ -d "$HOME/bin" ] && PATH="$PATH:$HOME/bin";

export PATH
40 changes: 40 additions & 0 deletions bin/backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

# IMPORTANT: Make sure you update the `DST` variable to
# match the name of the destination backup drive

PROG=$0
RSYNC="/usr/bin/rsync"
SRC="/"
DST="/Volumes/Macintosh HD/"
EXCLUDE="$HOME/.dotfiles/bin/backup_excludes.txt"

# -v increase verbosity
# -a turns on archive mode (recursive copy + retain attributes)
# -x don't cross device boundaries (ignore mounted volumes)
# -E preserve executability
# -S handle spare files efficiently
# --delete deletes any files that have been deleted locally
# --exclude-from reference a list of files to exclude
# --delete-excluded

if [ ! -r "$SRC" ]; then
/usr/bin/logger -t $PROG "Source $SRC not readable - Cannot start the sync process"
exit;
fi

if [ ! -w "$DST" ]; then
/usr/bin/logger -t $PROG "Destination $DST not writeable - Cannot start the sync process"
exit;
fi

/usr/bin/logger -t $PROG "Start rsync"

sudo $RSYNC -vaxE -S --delete --exclude-from=$EXCLUDE "$SRC" "$DST"

/usr/bin/logger -t $PROG "End rsync"

# make the backup bootable - comment this out if needed
sudo bless -folder "$DST"/System/Library/CoreServices

exit 0
15 changes: 15 additions & 0 deletions bin/backup_excludes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.Spotlight-*/
.Trashes
/afs/*
/automount/*
/cores/*
/dev/*
/Network/*
/private/tmp/*
/private/var/run/*
/private/var/spool/postfix/*
/private/var/vm/*
/Previous Systems.localized
/tmp/*
/Volumes/*
*/.Trash

0 comments on commit 98c00a8

Please sign in to comment.