#!/bin/bash
# fix 2006/11/21 by [email protected]
set -x
export LANG=C
host_name="wwwtst"
db_user=bacuser
db_pass=bacuser123456
bac_dir="/var/bac/$host_name"
[ -d $bac_dir ] || mkdir -p $bac_dir
cd $bac_dir
if [ 6 = 6 ]; then
#if [ `date +%w` = 6 ]; then
rm mysqldumpall-$host_name-`date –date="7 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$host_name-`date –date="6 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$host_name-`date –date="5 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$host_name-`date –date="4 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$host_name-`date –date="3 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$host_name-`date –date="2 day ago" +%F`.sql.tar.gz
rm mysqldumpall-$host_name-`date –date="1 day ago" +%F`.sql.tar.gz
/usr/local/mysql/bin/mysqldump -u $db_user -p$db_pass -A –opt > mysqldumpall-$host_name-`date +%F`.sql
tar zcvf mysqldumpall-$host_name-`date +%F`.sql.tar.gz mysqldumpall-$host_name-`date +%F`.sql
rm mysqldumpall-$host_name-`date +%F`.sql
else
[ -f mysqldumpall-$host_name-`date +%F`.sql.tar.gz ] && exit 0
/usr/local/mysql/bin/mysqldump -u $db_user -p$db_pass -A –opt > mysqldumpall-$host_name-`date +%F`.sql
tar zcvf mysqldumpall-$host_name-`date +%F`.sql.tar.gz mysqldumpall-$host_name-`date +%F`.sql
rm mysqldumpall-$host_name-`date +%F`.sql
fi
留言