In an ongoing effort to document my Ubuntu Linux backup strategies, I felt I should post my latest evolution in my daily cron script. I have modified the stock script I found and have documented in earlier posts to use compression via gzip. I also have modified the script to write the daily file into a subdirectory that is then uploaded to an Ubuntu FTP server via a crontab entry and a FTP macro in my .netrc file.
The modifications are simple and slight. I changed the tar command from -cf to -czf to engage the gzip capabilities of tar. I also added one variable, 'FILENAME' to my script. This file tracks the tar.gz filename and is used to write a copy of that file to a subdirectory of my main /backup directory. I do this so I can upload only the daily file to my FTP site, as I was uploading all the .tar files each night... not really a problem, but the inefficiencies of that were bugging me. Here is the script in full as it stands (Current OS is Ubuntu 7.10 Desktop):
#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan
# and modified by Iain McMullin>#Change the 5 variables below to fit your computer/backup (currently set for Ubuntu)
COMPUTER=computer-name # name of this computer
DIRECTORIES="/var/opt/axigen /etc/opt/axigen" # directories to backup
BACKUPDIR=/backups # where to store the backups
TIMEDIR=/backups/last-full # where to store time of full backup
TAR=/bin/tar # name and locaction of tar
FILENAME="" # placeholder for filename#You should not have to change anything below here
PATH=/usr/local/bin:/usr/bin:/bin
DOW=`date +%a` # Day of the week e.g. Mon
DOM=`date +%d` # Date of the Month e.g. 27
DM=`date +%d%b` # Date and Month e.g. 27Sep# On the 1st of the month a permanet full backup is made
# Every Sunday a full backup is made - overwriting last Sundays backup
# The rest of the time an incremental backup is made. Each incremental
# backup overwrites last weeks incremental backup of the same name.
#
# if NEWER = "", then tar backs up all files in the directories
# otherwise it backs up files newer than the NEWER date. NEWER
# gets it date from the file written every Sunday.# clean out the daily directory
rm $BACKUPDIR/current/*.gz# Monthly full backup
if [ $DOM = "01" ]; then
NEWER=""
FILENAME=$COMPUTER-$DM.tar.gz
$TAR $NEWER -czf $BACKUPDIR/$COMPUTER-$DM.tar.gz $DIRECTORIES
fi# Weekly full backup
if [ $DOW = "Sun" ]; then
NEWER=""
NOW=`date +%d-%b`# Update full backup date
echo $NOW > $TIMEDIR/$COMPUTER-full-date
FILENAME=$COMPUTER-$DOW.tar.gz
$TAR $NEWER -czf $BACKUPDIR/$COMPUTER-$DOW.tar.gz $DIRECTORIES# Make incremental backup - overwrite last weeks
else# Get date of last full backup
NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`"
FILENAME=$COMPUTER-$DOW.tar.gz
$TAR $NEWER -czf $BACKUPDIR/$COMPUTER-$DOW.tar.gz $DIRECTORIES
fi# copy new backup .gz file to directory for upload
cp $BACKUPDIR/$FILENAME $BACKUPDIR/current/$FILENAME
Delicious
Digg
Reddit
Technorati