[clug] backup script?

Randall Crook rcrook at vtown.com.au
Fri Aug 29 23:43:39 GMT 2008


Hi,

I have a very simple backup script using tar to dump the directories i
want to a 40GB DAT Tape.

It uses exclude and include files to specify what I want backed up.

Script looks like this:

#!/bin/bash
#set -x
LOG=/var/log/backup/backup.log
TAPE=/dev/st0
DATE=`date +%G-%m-%d`
LIST=/var/log/backup/${DATE}.log
INCL=/usr/local/etc/backup.include
EXCL=/usr/local/etc/backup.exclude
MAIL=/tmp/bu.txt
#
#
#
cd /
echo "--------------" >>$LOG 2>&1
echo "--------------" >>$MAIL 2>&1
echo "Starting backup $DATE `date +%H:%M:%S`." >>$LOG 2>&1
echo "Starting backup $DATE `date +%H:%M:%S`." >>$MAIL 2>&1
#
#
#
(tar cfb - 64 -X $EXCL -T $INCL | dd of=$TAPE bs=64k) >>$LOG 2>&1
if [ $? != 0 ]
then
   echo "ERR: Write to tape failed. $DATE `date +%H:%M:%S`" >>$LOG 2>&1
   echo "ERR: Write to tape failed. $DATE `date +%H:%M:%S`" >>$MAIL 2>&1
   echo "--------------" >>$LOG 2>&1
   echo "--------------" >>$MAIL 2>&1
   mailx -s "****Local Backup phoenix $DATE ****ERROR" rcrook <$MAIL
   rm -f $MAIL
   exit 1
fi
echo "Write to tape complete. $DATE `date +%H:%M:%S`" >>$LOG 2>&1
echo "Write to tape complete. $DATE `date +%H:%M:%S`" >>$MAIL 2>&1
#
#
#
echo "--------------" >>$LOG 2>&1
echo "--------------" >>$MAIL 2>&1
echo "Starting Verify $DATE `date +%H:%M:%S`." >>$LOG 2>&1
echo "Starting Verify $DATE `date +%H:%M:%S`." >>$MAIL 2>&1
(dd if=$TAPE bs=64k | tar tvf -) >$LIST 2>>$LOG
if [ $? != 0 ]
then
   echo "ERR: Verify of tape failed. $DATE `date +%H:%M:%S`" >>$LOG 2>&1
   echo "ERR: Verify of tape failed. $DATE `date +%H:%M:%S`" >>$MAIL 2>&1
   echo "--------------" >>$LOG 2>&1
   echo "--------------" >>$MAIL 2>&1
   mailx -s "****Local Backup phoenix $DATE ****ERROR" rcrook <$MAIL
   rm -f $MAIL
   exit 1
fi
echo "Verify of tape complete. $DATE `date +%H:%M:%S`" >>$LOG 2>&1
echo "Verify of tape complete. $DATE `date +%H:%M:%S`" >>$MAIL 2>&1
echo "--------------" >>$LOG 2>&1
echo "--------------" >>$MAIL 2>&1
gzip -9 $LIST
mailx -s "Local Backup phoenix $DATE" rcrook <$MAIL
rm -f $MAIL
#
# End Of backup
#

backup.include looks like:

etc
var
home
net/publish
share/priv
share/shared/data

and backup exclude looks like:

.svn
.thumbnails
tmp
dev
temp
proc
sys
export
remote
backup

as you can see I knocked it up in a few minutes. I did have to mess a
bit with the blocking factor on tar and dd to get the best performance
from the DAT drive, but it has saved my butt on a couple of occasions
already. I have it running once a week from cron.

It could be adapted to dump to a single file instead of a tape, then
burn the file off to dvd.

Anyway I hope it helps.

Randall.

Paul wrote:
> I've been wanting to figure out the best backup method, which in my
> opinion revolves around easiest restore method.
> I've just had to replace a HDD recently so this bumped this up the
> priority list.
>
> Initially I thought some sort of tar command , but presumably I would
> have to filter out the run-time files eg /proc /tmp etc..
> Has anyone got a working script that I could use?
>
> The other method which I'm wondering about is some sort of image
> backup of the whole drive, as this would make restore alot easier, right?
> Note my root drive current holds about 5Gb of data so it could
> possibly fit onto a DVD if I squeeze/zip it, but mostly I will just
> copy backup file to another mounted drive.
>
>
>
> Any thoughts.


-- 


More information about the linux mailing list