#!/bin/bash
if
[ -f
/etc/bkp
.conf ];
then
source
/etc/bkp
.conf ;
else
echo
/etc/bkp
.conf not found;
exit
;
fi
DATE=`
date
+%Y-%m-%d`
STATFILE=
/BACKUP/stat/
$HOST.stat
rm
$STATFILE
touch
$STATFILE
BACKUPDIR=
/BACKUP/
$HOST/
LASTDATE=`
date
+%Y-%m-%d --
date
=
"$DAYS days ago"
`
if
[ -d /$BACKUPDIR/$LASTDATE ];
then
rm
-rf /$BACKUPDIR/$LASTDATE ;
fi
echo
$HOST >>
/BACKUP/backuplog/
$HOST-backup.log
date
>>
/BACKUP/backuplog/
$HOST-backup.log
mkdir
/$BACKUPDIR/$DATE
MDB=$BACKUPDIR/$DATE
/mysql/
if
[
"$EXCLUDE"
!=
""
];
then
tar
-cjf /$BACKUPDIR/$DATE
/backup
.
tar
.bz2 --exclude=$EXCLUDE $DIRS
else
tar
-cjf /$BACKUPDIR/$DATE
/backup
.
tar
.bz2 $DIRS
fi
STAT=$?
echo
$STAT>>
/BACKUP/backuplog/
$HOST-backup.log
echo
FS $STAT $DATE >>$STATFILE
if
[ $MYSQLBACKUP = 0 ];
then
date
>>
/BACKUP/backuplog/
$HOST-backup.log
exit
;
fi
mkdir
/$BACKUPDIR/$DATE
/mysql/
STAT=0
DBS=
"$(mysql -u$MYSQLUSER -p$MYSQLPASSWD -Bse 'show databases')"
for
db
in
$DBS
do
skipdb=-1
if
[
"$EXCLUDEDB"
!=
""
];
then
for
i
in
$EXCLUDEDB
do
[
"$db"
==
"$i"
] && skipdb=1 || :
done
fi
if
[
"$skipdb"
==
"-1"
] ;
then
FILE=
"$MBD/$db.$HOST.$NOW.gz"
mysqldump -u$MYSQLUSER -p$MYSQLPASSWD $db |
bzip2
>$MDB/$db.sql.bz2
STAT=$?
echo
$db $STAT>>
/BACKUP/backuplog/
$HOST-backup.log
echo
DB $db $STAT>>$STATFILE
fi
done
date
>>
/BACKUP/backuplog/
$HOST-backup.log