You are not logged in.
Pages: 1
Been playing with a backup script I found on the internet. Loved it, so I modified it to auto backup to a directory, gzip and then copy to tape drive. Pretty simple script. Hopefully someone will find it usefull. I tried to comment to the best of my ability, but we know how the brain works sometimes.
I also have an almost auto backup to DVD that I will post at a later date.
#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@freebsd.org>
# and modified by Gerhard Mourani <gmourani@videotron.ca>
# and modified by Shaun Mcbride for mcbride.homelinux.net <mcbride@mcbride.homelinux.net>
# Found this script thourht it would be perfect for some type of backup solution for small amounts of data.
# Was using a script to dump mysql databases to /home/backups and then depending on the day of the week
# the script will gzip the tar file and copy it to MON TUE type directory structure. After the gzip was done
# it would then backup it up to /dev/st0 due to the small file sizes I could keep multiple copies arond for
# a long time before the tape drive became full. But I was wrong. Mysql database out grew the tapes.
# Hopefully someone will find this usefull.
# You can also work /dev/nst0 if you don't want the tape to rewind each time you backup.
# But this will cause the tape to fill up pretty fast using this script.
#Change the 5 variables below to fit your computer/backup
#Must have last-full directory and 1 simple file. Must be the name of COMPUTER-full-date.
#Must also contain a date in the format of "01-Jan" without the quotes of course.
COMPUTER=mysql_backup # name of this compute
DIRECTORIES="/home/backups" # directoris to backup must have quotes
BACKUPDIR=/home/backups/server/ # where to store the backups
TIMEDIR=/home/backups/server/last-full # where to store time of full backup
TAR=/bin/tar # name and locaction of tar
#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.
#This will consume alot of disk space if left unchecked.
# Monthly full backup
if [ $DOM = "01" ]; then
NEWER=""
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DM.tar $DIRECTORIES
cp $BACKUPDIR/$COMPUTER-$DM.tar $BACKUPDIR/gz/monthly/$COMPUTER-$DM.tar
gzip $BACKUPDIR/gz/monthly/$COMPUTER-$DOW-$DM.tar
fi
#Above will gzip and move to the montly directory. But won't copy to data tape.
#Will have to do that manually. With something like "tar cf /dev/st0 /my/monthly && mt -f /dev/st0 eject"
# Weekly full backup
if [ $DOW = "Sun" ]; then
NEWER=""
NOW=`date +%d-%b`
# Update full backup date
echo $NOW > $TIMEDIR/$COMPUTER-full-date
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES
cp $BACKUPDIR/$COMPUTER-$DOW.tar $BACKUPDIR/gz/SUN/$COMPUTER-$DOW-$DM.tar
gzip $BACKUPDIR/gz/SUN/$COMPUTER-$DOW-$DM.tar
tar cf /dev/st0 $BACKUPDIR/gz/SUN/
mt -f /dev/st0 eject
#You could use $DOW instead of SUN in the directory above. But doesn't make a difference.
#Above will alos gzip and copy to a specific directory to be backedup
# Make incremental backup - overwrite last weeks
# This use to overwrite the previous weeks backup - that is not the case anymore.
# It only overwrites the tar file only. But below the first else statement, the
# script gzip's the tar file and moves it to a directory.
else
# Get date of last full backup
NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`"
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES
fi
if [ $DOW = "Mon" ]; then
cp $BACKUPDIR/$COMPUTER-$DOW.tar $BACKUPDIR/gz/MON/$COMPUTER-$DOW-$DM.tar
gzip $BACKUPDIR/gz/MON/$COMPUTER-$DOW-$DM.tar
tar cf /dev/st0 $BACKUPDIR/gz/MON/
mt -f /dev/st0 eject
fi
if [ $DOW = "Tue" ]; then
cp $BACKUPDIR/$COMPUTER-$DOW.tar $BACKUPDIR/gz/TUE/$COMPUTER-$DOW-$DM.tar
gzip $BACKUPDIR/gz/Tue/$COMPUTER-$DOW-$DM.tar
tar cf /dev/st0 $BACKUPDIR/gz/TUE/
mt -f /dev/st0 eject
fi
if [ $DOW = "Wed" ]; then
cp $BACKUPDIR/$COMPUTER-$DOW.tar $BACKUPDIR/gz/WED/$COMPUTER-$DOW-$DM.tar
gzip $BACKUPDIR/gz/WED/$COMPUTER-$DOW-$DM.tar
tar cf /dev/st0 $BACKUPDIR/gz/WED/
mt -f /dev/st0 eject
fi
if [ $DOW = "Thu" ]; then
cp $BACKUPDIR/$COMPUTER-$DOW.tar $BACKUPDIR/gz/THU/$COMPUTER-$DOW-$DM.tar
gzip $BACKUPDIR/gz/THU/$COMPUTER-$DOW-$DM.tar
tar cf /dev/st0 $BACKUPDIR/gz/THU/
mt -f /dev/st0 eject
fi
if [ $DOW = "Fri" ]; then
cp $BACKUPDIR/$COMPUTER-$DOW.tar $BACKUPDIR/gz/FRI/$COMPUTER-$DOW-$DM.tar
gzip $BACKUPDIR/gz/FRI/$COMPUTER-$DOW-$DM.tar
tar cf /dev/st0 $BACKUPDIR/gz/FRI/
mt -f /dev/st0 eject
fi
if [ $DOW = "Sat" ]; then
cp $BACKUPDIR/$COMPUTER-$DOW.tar $BACKUPDIR/gz/SAT/$COMPUTER-$DOW-$DM.tar
gzip $BACKUPDIR/gz/SAT/$COMPUTER-$DOW-$DM.tar
tar cf /dev/st0 $BACKUPDIR/gz/SAT/
mt -f /dev/st0 eject
fi
Offline
Pages: 1