Here is (one of!) my own backup script. At it's core, it uses tar
for
performing the backup.
It's not one of my all time great pieces of code. Prizes 1 will be awarded for anyone who can work out what it does 2.
# -*-sh-*- BACKUP_DIR=//linkstn/share/home-backup/ ## make a back up my home space if cd $BACKUP_DIR then echo [backup] Backing up to `pwd` else echo "Failed to change to backup directory" exit 1 fi ## transfer the cvs repository over to this machine, so that I can package it up from here. BACKUP_FLAG=~/bin/local/last-backup BACKUP_FULL_FLAG=~/bin/local/full-backup TAR=tar #TAR_OPTIONS= TAR_OPTIONS="vc -T -" RM=rm FIND=find FIND_GENERAL_OPTIONS="-type f" FIND_INCREMENTAL_OPTIONS="-newer $BACKUP_FLAG" FIND_HOME_OPTIONS="" FIND_EXTRA_OPTIONS="" FULL_BACKUP_FLAG=false DATE_STRING=`date +%y_%m_%d_%H_%M` DATE_DELETE="+%y_%m_%d" ## Set options up for full backup. if [ ! -e $BACKUP_FLAG ]; then FIND_LOCAL_OPTIONS="" FULL_BACKUP_FLAG=true echo [backup] Full Backup else FIND_LOCAL_OPTIONS=$FIND_INCREMENTAL_OPTIONS fi FIND_OPTIONS="$FIND_GENERAL_OPTIONS $FIND_LOCAL_OPTIONS" echo [backup] Back up home space, to $DATE_STRING.tgz #mkdir $DATE_STRING.tgz echo $FIND ~ $FIND_HOME_OPTIONS $FIND_OPTIONS $FIND ~/ $FIND_HOME_OPTIONS $FIND_OPTIONS | \ $TAR $TAR_OPTIONS | gzip -9 > $DATE_STRING.tgz ## can't work this out, but the above command seems to be creating ## files with date stamps of 2002. This breaks the delete below. touch $DATE_STRING.tgz echo [backup] Home space complete ## if we doing full backups and it exists, delete all things older ## than last full backup ## oh dear not well named vars if [ -e $BACKUP_FULL_FLAG ] && $FULL_BACKUP_FLAG; then echo [backup] Removing old backups ## we should already be in this directory, but try to cd ## again. This way if network has broken during the backup, we ## will be protected. if cd $BACKUP_DIR then echo [backup] Deleting files from `pwd` else echo "Failed to change to backup directory" exit 1 fi # have to do this in two steps else find complains about the # directories that it has already deleted find . -type f -not -newer $BACKUP_FULL_FLAG -print -exec rm {} \; # find . -type d -not -newer $BACKUP_FULL_FLAG -print -exec rmdir {} \; fi if $FULL_BACKUP_FLAG; then if [ -e $BACKUP_FULL_FLAG.1 ]; then cp --preserve $BACKUP_FULL_FLAG.1 $BACKUP_FULL_FLAG fi if [ -e $BACKUP_FULL_FLAG.2 ]; then cp --preserve $BACKUP_FULL_FLAG.2 $BACKUP_FULL_FLAG.1 fi if [ -e $BACKUP_FULL_FLAG.3 ]; then cp --preserve $BACKUP_FULL_FLAG.3 $BACKUP_FULL_FLAG.2 fi echo [backup] Updating full backup flag touch $BACKUP_FULL_FLAG.3 fi echo [backup] Updating backup flag touch $BACKUP_FLAG echo [backup] Complete
1. You will go home with a warm glow in your heart.
2. You won't be able to work this out by just running it. It doesn't work on actually work on linux.