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
3 comments:
Hello,
Thank you a lot for your backup script! However i get problems when using Ubuntu 8.04:
rm: cannot remove `/data/backups/current/*.gz': No such file or directory
cat: /data/backups/last-full/domus-full-date: No such file or directory
/bin/tar: Substituting 1901-12-13 21:05 for unknown date format `-czf'
/bin/tar: You must specify one of the `-Acdtrux' options
Try `/bin/tar --help' or `/bin/tar --usage' for more information.
cp: cannot stat `/data/backups/domus-Sat.tar.gz': No such file or directory
Can you help me?
Regards,
Dennis
Looks like you didn't create the full-date file. You have to either run the command, or run it by hand. Also, this script is only tested with US date... If you have non standard characters in your date format, that may cause issues.
I suggest debugging by writing the variables to a file >> filename.txt to see what is in each variable. Also, make sure you're testing as sudo...
I just verified this on my 8.04 server. You need to create the /last-full directory and create the file (I used touch). Then run the date +%d%b > /your backup dir/last-full/myserver-full-date command.
All will work after that!
Post a Comment