#! /bin/bash # rsync_bak (Bash script) -- does full/incremental backups using rsync # .rsync_bak_exclude files (anywhere in the trees) specify files/directories/ # wildcards to be excluded. (Watch out for relative paths; they will match # anywhere in the tree. Start a path with "/" to anchor it to the the location # of the .rsync_bak_exclude file.) # # Version: 1.8.2 syslog_facility=daemon syslog_tag="rsync_bak[$$]" files="/etc /home /usr/local /var/log /var/spool /var/mail /var/lib/bluetooth /var/lib/samba" rsync_module=fomalhaut::`hostname`_backup new_dir_name=`date +%Y%m%d` logger -t $syslog_tag -p $syslog_facility.info backing up $files to $rsync_module # find the name of the previous backup # (assumes there are no other kinds of file or directory at the root of # the module with a name that starts with a digit) old_dir_name=`rsync $rsync_module/'[0-9]*'|awk '{ name = $5 } END { print name }' ; exit ${PIPESTATUS[0]}` if [ $? -eq 0 ] ; then logger -t $syslog_tag -p $syslog_facility.debug incremental backup relative to $old_dir_name else logger -t $syslog_tag -p $syslog_facility.err relative directory lookup failed exit 1 fi # the main rsync invocation # (includes options to conduct incremental backup using hard links # and to, after the transfer, delete files that have been deleted here or # added to the exclude list) rsync -avS \ --link-dest=../$old_dir_name --delete --delete-excluded --delete-after \ --exclude='*~' --exclude=.DS_Store --exclude=.FBCLockFolder --exclude=.gvfs \ --exclude=.ccache --exclude=.beagle --exclude=.cache \ --exclude=.xvpics --exclude='#*#' --exclude='.*.sw?' \ --exclude='.~lock.*#' \ --exclude='/home/*/.mozilla/*/*/Cache*' --exclude='/home/*/.prism/*/*/Cache*' \ --exclude='/home/*/.mozilla/*/*/*.mfasl' --exclude='/home/*/.mozilla/*/*/history.dat.old' --exclude='/home/*/.mozilla/*/*/*.bak' --exclude='/home/*/.mozilla/*/*/urlclassifier*.sqlite' \ --exclude='/home/*/.gnome2/epiphany/mozilla/epiphany/Cache' --exclude='/home/*/.java/deployment/cache' \ --exclude='/home/*/.kde/share/apps/kmail/dimap' \ --exclude='/home/*/.thumbnails' --exclude='/home/*/.Trash' \ --exclude='/home/*/.openoffice.org2/user/config/imagecache' \ --exclude='/home/*/.openoffice.org/3/user/uno_packages' --exclude='/home/*/.openoffice.org2/user/registry/cache' \ --exclude='/home/*/.kde/share/apps/nepomuk/repository' \ --exclude='/home/*/.local/share/desktop-couch/.gwibber_messages_design' \ --exclude=/etc/brltty --exclude=/etc/gconf/gconf.xml.defaults \ --exclude='/usr/local/src' \ --filter=":- .rsync_bak_exclude" \ $files $rsync_module/$new_dir_name rsync_exitcode=$? if [ $rsync_exitcode -eq 0 ] ; then logger -t $syslog_tag -p $syslog_facility.notice backup complete else logger -t $syslog_tag -p $syslog_facility.err backup failed with error code $rsync_exitcode exit 2 fi