Subject | Re: Backup on Linux |
---|---|
Author | Ian A. Newby |
Post date | 2005-08-11T11:40:04Z |
Hi Jobrian,
I use the following script (between the xxx's):
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#!/bin/bash
BASE_TARGET=/data/Backup
SOURCE_FILE_DIR=/root/backup/source
EMAIL=iann@...,nathan@...
today=`date +%w`
if [ "$today" = "0" ]; then
today=Week`date +%V`
ls -tl $BASE_TARGET | grep -E "^Week[0-9]?[0-9]/$" | tail -n +5 |
xargs rm -fR
else
today=`date +%A`
fi
mkdir $BASE_TARGET/$today 2>/dev/null
rm $BASE_TARGET/Current -f 2>/dev/null
ln -s $BASE_TARGET/$today $BASE_TARGET/Current
BASE_TARGET=$BASE_TARGET/Current
for destination in `ls $SOURCE_FILE_DIR`
do
echo $destination
while read database
do
DATABASE=(${database})
source=${DATABASE[0]}
target=`basename $source`
target=$BASE_TARGET/${target%.???}.fbk
user=${DATABASE[1]}
password=${DATABASE[2]}
/opt/interbase/bin/gbak -B -user $user -password $password $source
$target 2> backup.err
/opt/interbase/bin/gbak -C -user $user -password $password $target
$BASE_TARGET/restore.fdb 2>> backup.err
rm -f $BASE_TARGET/restore.fdb
if [ -s $backup.err ]; then
echo "Problem backing up or restoring"
mail -s "Error backing up $source on
$destination" $EMAIL < backup.err
fi
done < $SOURCE_FILE_DIR/$destination
tar -czf $BASE_TARGET/$destination.tgz $BASE_TARGET/*.fbk
rm -f $BASE_TARGET/*.fbk
done
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
It creates a directory under the BASE_TARGET with the name of the
control file and then creates a directory
of either the day of the week or the weeknumber (if sunday).
into this directory it backs up, restores and tars the file.
If any error occurs, it emails the specified users.
It also creates a softlink to the most current backup.
It needs control files in SOURCE_FILE directory like the following:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
/DataSafe/aktiv.fdb <username> <password>
/DataSafe/TMILeanMan.gdb username> <password>
/DataSafe/TMI_PSC.gdb username> <password>
/DataSafe/awards.fdb username> <password>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You can then schedule this with cron.
Hope this helps
Regards
Ian Newby
I use the following script (between the xxx's):
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#!/bin/bash
BASE_TARGET=/data/Backup
SOURCE_FILE_DIR=/root/backup/source
EMAIL=iann@...,nathan@...
today=`date +%w`
if [ "$today" = "0" ]; then
today=Week`date +%V`
ls -tl $BASE_TARGET | grep -E "^Week[0-9]?[0-9]/$" | tail -n +5 |
xargs rm -fR
else
today=`date +%A`
fi
mkdir $BASE_TARGET/$today 2>/dev/null
rm $BASE_TARGET/Current -f 2>/dev/null
ln -s $BASE_TARGET/$today $BASE_TARGET/Current
BASE_TARGET=$BASE_TARGET/Current
for destination in `ls $SOURCE_FILE_DIR`
do
echo $destination
while read database
do
DATABASE=(${database})
source=${DATABASE[0]}
target=`basename $source`
target=$BASE_TARGET/${target%.???}.fbk
user=${DATABASE[1]}
password=${DATABASE[2]}
/opt/interbase/bin/gbak -B -user $user -password $password $source
$target 2> backup.err
/opt/interbase/bin/gbak -C -user $user -password $password $target
$BASE_TARGET/restore.fdb 2>> backup.err
rm -f $BASE_TARGET/restore.fdb
if [ -s $backup.err ]; then
echo "Problem backing up or restoring"
mail -s "Error backing up $source on
$destination" $EMAIL < backup.err
fi
done < $SOURCE_FILE_DIR/$destination
tar -czf $BASE_TARGET/$destination.tgz $BASE_TARGET/*.fbk
rm -f $BASE_TARGET/*.fbk
done
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
It creates a directory under the BASE_TARGET with the name of the
control file and then creates a directory
of either the day of the week or the weeknumber (if sunday).
into this directory it backs up, restores and tars the file.
If any error occurs, it emails the specified users.
It also creates a softlink to the most current backup.
It needs control files in SOURCE_FILE directory like the following:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
/DataSafe/aktiv.fdb <username> <password>
/DataSafe/TMILeanMan.gdb username> <password>
/DataSafe/TMI_PSC.gdb username> <password>
/DataSafe/awards.fdb username> <password>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You can then schedule this with cron.
Hope this helps
Regards
Ian Newby