#!/bin/bash -x # Backup OSX # Modified from: http://ask.slashdot.org/askslashdot/06/12/16/0656212.shtml # see also: http://www.egg-tech.com/mac_backup/ # http://blog.plasticsfuture.org/2006/04/23/mac-backup-software-harmful/ # Author: Steven Thomas Smith , 2007-03-17: Version 0.1 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA DEST="/Volumes/LaCie Partition 2" BACKUP_NAME="computername_backup" EXCLUDES_FILE="/Users/stsmith/bin/.makebackup_excludes.txt" # example excludes file: ### /tmp/* ### /Network/* ### /cores/* ### */.Trash ### /afs/* ### /automount/* ### /private/tmp/* ### /private/var/run/* ### /private/var/spool/postfix/* ### /private/var/vm/* ### /Previous Systems.localized ### /.Spotlight-*/ ### /Users/*/Library/Caches # To use Apple's rsync switch commented lines below # To use rsyncx: # RSYNC=/usr/local/bin/rsync --eahfs --showtogo # To use built-in rsync (OS X 10.4 and later): RSYNC="/usr/bin/rsync -E -v" # Function for toggling Spotlight indexing spotlight_switch() { /usr/bin/mdutil -i $1 / # /usr/bin/mdutil -i $1 /Volumes/Backups } # sudo runs the backup as root # --eahfs enables HFS+ mode # -a turns on archive mode (recursive copy + retain attributes) # -x don't cross device boundaries (ignore mounted volumes) # -S handle sparse files efficiently # --showtogo shows the number of files left to process # --delete deletes any files that have been deleted locally # $* expands to any extra command line options you may give # make sure we're running as root # id options are effective (u)ser ID if (( `id -u` != 0 )); then { echo "Sorry, must be root. Exiting..."; exit; } fi; ! test -d "$DEST" && echo "Please mount the backup drive!" && exit spotlight_switch off rm -rf "$DEST"/"$BACKUP_NAME"_2 mv "$DEST"/"$BACKUP_NAME"_1 "$DEST"/"$BACKUP_NAME"_2 mv "$DEST"/"$BACKUP_NAME" "$DEST"/"$BACKUP_NAME"_1 $RSYNC -a -x -S --delete --link-dest=../"$BACKUP_NAME"_1 \ --exclude-from "$EXCLUDES_FILE" $* / "$DEST"/"$BACKUP_NAME" # make the backup bootable - comment this out if needed bless -folder "$DEST"/"$BACKUP_NAME"/System/Library/CoreServices spotlight_switch on