Top: Index 

CSC8306 -- Systems Administration

This is my real, live, backup script. It's difficult, overly complex and has the history of backup rules from the past incorporated. Please read it in this light!

# -*-sh-*-

echo [backup] Local unison
#unison -batch yarm-duplicate
unison -batch all-selset-no-ignore

## ssh-agents that I have started with ssh-login will time out. Stop these and
## start another which will carry on for ever. Otherwise, latter stuff will
## fail.
ssh-login


## unmount crypted file system
##echo [backup] umounting crypt
##fusermount -uz ~/crypt
##fusermount -uz ~/storages

echo [backup] Update home page
update_homepage

echo [backup] Fetching calendar
fetch_calendar


## transfer the cvs repository over to this machine, so that I can package it up from here.
BACKUP_FLAG=~/bin/last-backup-man
BACKUP_SUNDAY_FULL_DONE=~/bin/sunday-backup-man


TAR=tar
#TAR_OPTIONS=
TAR_OPTIONS="vc -T -"
RM=rm
FIND=find

DOW=`date +%a`              # Day of the week e.g. Mon
DOM=`date +%d`

## only find files (directories will be included anyway -- tar creates
## them for files) and don't follow other file systems.
FIND_GENERAL_OPTIONS=" -xdev -type f"
FIND_INCREMENTAL_OPTIONS="-newer $BACKUP_FLAG"

FIND_HOME_OPTIONS=""
FIND_EXTRA_OPTIONS=""

## backup type
BACKUP_TYPE="inc"

## as I have so many other backups, I think I will start doing incrementals
## all the time. It's the history, the ability to revert, I want here, not the
## backup per se.
FIND_LOCAL_OPTIONS=$FIND_INCREMENTAL_OPTIONS

# ## Set options up for full backup.
# if [ $DOW = "Fri" ] || [ ! -e $BACKUP_FLAG ]; then

#     # we only want to do a full back up once on sunday
#     if [ ! -e $BACKUP_SUNDAY_FULL_DONE ]; then
#         FIND_LOCAL_OPTIONS=""
#         echo [backup]  Full Backup
#         BACKUP_TYPE="full"
#         touch $BACKUP_SUNDAY_FULL_DONE
#     else
#         echo [backup]  Second backup on sunday!
#         FIND_LOCAL_OPTIONS=$FIND_INCREMENTAL_OPTIONS
#     fi
# else
#     # remove the sunday backup flag
#     if [ -e $BACKUP_SUNDAY_FULL_DONE ]; then
#         rm $BACKUP_SUNDAY_FULL_DONE
#     fi
#     FIND_LOCAL_OPTIONS=$FIND_INCREMENTAL_OPTIONS
# fi


if [ $BACKUP_TYPE = "full" ]; then
    echo [backup] Dumping blogs for full backup
    dump_blogs
fi

FIND_OPTIONS="$FIND_GENERAL_OPTIONS $FIND_LOCAL_OPTIONS"
echo [backup] Find command $FIND $FIND_OPTIONS


DATE_STRING=`date +%y_%m_%d_%H_%M`
DATE_DELETE="+%y_%m_%d"


RSYNC_OPTIONS="-vrtz --delete"

## put here those directories I don't want to search. If there is more than one then prepend each with -e
IGNORED_DIRECTORIES='/phillord/.mozilla\|phillord/mnt\|phillord/.cpan\|phillord/.wine\|phillord/transfer\|phillord/crypt\|phillord/scratch\|phillord/.cedega\|phillord/.Trash\|phillord/.crypt\|phillord/pictures-extra\|phillord/.gvfs\|phillord/.local'

# ## change into the right directory, or the find puts on /home/phillord which screws up rsync
# cd /
# $FIND ~ $FIND_HOME_OPTIONS $FIND_GENERAL_OPTIONS | grep --invert-match $IGNORED_DIRECTORIES | \
#    rsync -e ssh $RSYNC_OPTIONS --files-from=- . phillord@carmen-raid.ncl.ac.uk:dinley-home
#
# echo [backup] Pushing Home to Carmen
# rsync-to-carmen


## this will be one backup out of sync -- needs to be done here, though,
## because the ssh-agent keeps timing out. So we need to do this first.

## decided to disable this -- I've never used it, and it costs a lot of
## network traffic, as well as network space
#echo [backup] Pushing Backup to Carmen
#rsync -e ssh $RSYNC_OPTIONS /backup phillord@carmen-raid.ncl.ac.uk:dinley-backup


## now we are going to backup my home space.
if cd /backup
    then
    echo [backup] Backing up to `pwd`
else
    echo "Failed to change to backup directory"
    exit 1
fi




echo [backup]  Back up home space to `pwd` backup_$DATE_STRING.tgz
echo $FIND /home/phillord/ $FIND_HOME_OPTIONS $FIND_OPTIONS  grep --invert-match $IGNORED_DIRECTORIES
$FIND /home/phillord/ $FIND_HOME_OPTIONS $FIND_OPTIONS | grep --invert-match $IGNORED_DIRECTORIES \
    | $TAR $TAR_OPTIONS | gzip -9 > backup_$DATE_STRING.tgz
echo [backup]  Home space completes


## if I only ever do incrementals, I suspect that I will never need to delete these backups.
## echo [backup]  delete local old
## find . -type f -mtime +18 -name "backup*" -not -name "lost+found" -print -exec rm -rv {} \;



echo [backup] rss aggregating
r2e run

echo [backup]  updating backup flag
touch $BACKUP_FLAG


## complete unison to second hard drive
##unison -batch yarm-duplicate


echo [backup] Complete



Top: Index