Skip to content
Browse files

bin: Create a new bin including a backup script

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...
1 parent c23444e commit 98c00a8644873f51e0ce5833c6b6c197f5432b39 @necolas committed Apr 16, 2012
Showing with 58 additions and 3 deletions.
  1. +3 −3 bash/exports
  2. +40 −0 bin/backup.sh
  3. +15 −0 bin/backup_excludes.txt
View
6 bash/exports
@@ -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
View
40 bin/backup.sh
@@ -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
View
15 bin/backup_excludes.txt
@@ -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.
Something went wrong with that request. Please try again.