分类: Mysql/postgreSQL
2011-12-16 21:07:59
[root@e01 backup]# cat backup.sh
#!/bin/sh
#---------------------------------------------#
# File: /storage/db/backup/backup.sh
# Database info
#---------------------------------------------#
echo -e [`date +"%Y-%m-%d %H:%M:%S"`] start
DB_USER="root"
DB_PASS="gb52054.GB@"
#DB_NAME=`mysql -u "$user" -p "$DB_PASS" -Bse 'show databases'`
# Others vars
BIN_DIR="/software/mysql/bin"
BCK_DIR="/storage/db/backup"
DATE=`date +%F`
# TODO
find $BCK_DIR -name "*.gz" -mtime +15 |xargs rm -fv {} \;
find $BCK_DIR -name "*.sql" -mtime +15 |xargs rm -fv {} \;
find $BCK_DIR -name "*.gz" -mtime +10 |xargs -I {} mv {} /home/backup/source/ ;
find $BCK_DIR -name "*.sql" -mtime +10 |xargs -I {} mv {} /home/backup/source/ ;
for DB_NAME in carshow discuz jiebao
do
$BIN_DIR/mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > $BCK_DIR/$DB_NAME-db-$DATE.sql
done
cd /storage/data/htdocs
for source in carshow discuz jiebao
do
tar zcvf /storage/db/backup/$source-$DATE.tar.gz $source
done
echo -e [`date +"%Y-%m-%d %H:%M:%S"`] end
exit 0