#! /bin/sh # tarbak (Bourne shell script) -- does full/incremental backups using tar # The files are placed in /var/backup/ # "exclude" statements in the real user's .tarbakrc specify one # or more additional files/directories/wildcards to be excluded # # Version: 1.4 files="/etc /home /root /var/mail /usr/local /srv /boot/grub" backup_dir=/var/backup/`date +'%b%Y'` name_format=`uname -n`_`date +'%b%Y'` if [ -d $backup_dir ] ; then # Directory already exists; assume that the full backup has already been # done this month. # calculate the number of tarfiles aready in the directory; this # sequence number is one beyond that of the most recent incremental file seq=`ls $backup_dir/${name_format}* | wc -l` tarfile=${name_format}_`printf %02d $seq`.tar.gz # make a backup of the list file just in case it becomes screwed up due to a script error cp -p $backup_dir/list $backup_dir/list.bak else # Directory does not exist yet; create it and do a full backup mkdir -p $backup_dir tarfile=$name_format.tar.gz fi # a subcommand embeds a sed script that processes lines from .tarbak # starting with "exclude" and places them onto the tar command line as # --exclude options. (Filenames containing spaces must be quoted; the # outer 'qstringloop' label/test handles multiple quoted strings on a # line, whilst the inner 'spaceloop' label/test converts each space # within such a string to a question mark.) tar zc -g $backup_dir/list -f $backup_dir/$tarfile \ --exclude='*~' --exclude=.DS_Store --exclude=.FBCLockFolder --exclude=.gvfs \ --exclude=.ccache --exclude=.beagle --exclude=.cache \ --exclude=.xvpics --exclude='#*#' --exclude='.*.sw?' \ --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/*/.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 \ `if [ -f $HOME/.tarbakrc ] ; then sed -n -e "/^exclude/ {" -e :qstringloop -e :spaceloop -e 's/^\([^"]*"[^ "]*\) /\1?/' -e "t spaceloop" -e 's/"\([^"]*\)"/\1/' -e "t qstringloop" -e "s@ \([^/]\)@ $HOME/\1@g" -e "s/ / --exclude=/g" -e 's/^exclude//p' -e "}" $HOME/.tarbakrc ; fi` \ $files