一個簡單mysql 備份策略 。

season0891發表於2010-10-11
#!/bin/sh
BACKTIME=`date +%Y%m%d`
DELTIME=`date +%Y%m%d -d -7day`
echo "===================================$BACKTIME==================================="
if [ ! -d /backup/bak_mysqldata/$BACKTIME ]

then

        mkdir /backup/bak_mysqldata/$BACKTIME

fi

cd /backup/bak_mysqldata/$BACKTIME

#if [ ! -f /backup/bak_mysqldata/$BACKTIME/blog_db.sql ]
#then
#       bgdt=`date +%H:%M:%S`
#       /usr/local/mysql/bin/mysqldump blog_db > /backup/bak_mysqldata/$BACKTIME/blog_db.sql
#       eddt=`date +%H:%M:%S`
#       echo -e "$bgdt\tStart to dumping blog_db!"
#       echo -e "$eddt\tblog_db database dump finish!!!"
#fi

#if [ ! -f /backup/bak_mysqldata/$BACKTIME/dw_data_center.sql ]
#then
#       bgdt=`date +%H:%M:%S`
#       /usr/local/mysql/bin/mysqldump dw_data_center > /backup/bak_mysqldata/$BACKTIME/dw_data_center.sql
#       eddt=`date +%H:%M:%S`
#       echo -e "$bgdt\tStart to dumping dw_data_center!"
#       echo -e "$eddt\tdw_data_center database dump finish!!!"
#fi

if [ ! -f /backup/bak_mysqldata/$BACKTIME/dwnews_new_adsr1.sql ]
then
        bgdt=`date +%H:%M:%S`
        /usr/local/mysql/bin/mysqldump dwnews_new_adsr1 > /backup/bak_mysqldata/$BACKTIME/dwnews_new_adsr1.sql
        eddt=`date +%H:%M:%S`
        echo -e "$bgdt\tStart to dumping dwnews_new_adsr1!"
        echo -e "$eddt\tdwnews_new_adsr1 database dump finish!!!"
fi

if [ ! -f /backup/bak_mysqldata/$BACKTIME/dwnews_new_adsr2.sql ]
then
        bgdt=`date +%H:%M:%S`
        /usr/local/mysql/bin/mysqldump dwnews_new_adsr2 > /backup/bak_mysqldata/$BACKTIME/dwnews_new_adsr2.sql
        eddt=`date +%H:%M:%S`
        echo -e "$bgdt\tStart to dumping dwnews_new_adsr2!"
        echo -e "$eddt\tdwnews_new_adsr2 database dump finish!!!"
fi

if [ ! -f /backup/bak_mysqldata/$BACKTIME/dwnews_new_blog.sql ]
then
        bgdt=`date +%H:%M:%S`
        /usr/local/mysql/bin/mysqldump dwnews_new_blog > /backup/bak_mysqldata/$BACKTIME/dwnews_new_blog.sql
        eddt=`date +%H:%M:%S`
        echo -e "$bgdt\tStart to dumping dwnews_new_blog!"
        echo -e "$eddt\tdwnews_new_blog database dump finish!!!"
fi

if [ ! -f /backup/bak_mysqldata/$BACKTIME/dwnews_new_life.sql ]
then
        bgdt=`date +%H:%M:%S`
        /usr/local/mysql/bin/mysqldump dwnews_new_life > /backup/bak_mysqldata/$BACKTIME/dwnews_new_life.sql
        eddt=`date +%H:%M:%S`
        echo -e "$bgdt\tStart to dumping dwnews_new_life!"
        echo -e "$eddt\tdwnews_new_life database dump finish!!!"
fi

if [ ! -f /backup/bak_mysqldata/$BACKTIME/dw_shushang.sql ]
then
        bgdt=`date +%H:%M:%S`
        /usr/local/mysql/bin/mysqldump dw_shushang > /backup/bak_mysqldata/$BACKTIME/dw_shushang.sql
        eddt=`date +%H:%M:%S`
        echo -e "$bgdt\tStart to dumping dw_shushang!"
        echo -e "$eddt\tdw_shushang database dump finish!!!"
fi

if [ ! -f /backup/bak_mysqldata/$BACKTIME/mysql.sql ]
then
        bgdt=`date +%H:%M:%S`
        /usr/local/mysql/bin/mysqldump mysql > /backup/bak_mysqldata/$BACKTIME/mysql.sql
        eddt=`date +%H:%M:%S`
        echo -e "$bgdt\tStart to dumping mysql!"
        echo -e "$eddt\tmysql database dump finish!!!"
fi

if [ -f /backup/bak_mysqldata/$DELTIME.tgz ]
then
        bgdt=`date +%H:%M:%S`
        rm -rf /backup/bak_mysqldata/$DELTIME.tgz
        eddt=`date +%H:%M:%S`
        echo -e "$bgdt\tStart to delete backup on $DELTIME!"
        echo -e "$eddt\tbackup databases delete finish in $DELTIME !!!"
fi

cd /backup/bak_mysqldata/

if [ -d /backup/bak_mysqldata/$BACKTIME ]
then
        bgdt=`date +%H:%M:%S`
        echo -e "$bgdt\tStart to package dump files!"
        tar zcvf /backup/bak_mysqldata/$BACKTIME.tgz /backup/bak_mysqldata/$BACKTIME
        if [ -f /backup/bak_mysqldata/$BACKTIME.tgz ]
        then
                rm -rf /backup/bak_mysqldata/$BACKTIME
        fi
        eddt=`date +%H:%M:%S`
        echo -e "$eddt\tPacking dump file is finished!"

fi
[root@rac2 ~]#

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-675704/,如需轉載,請註明出處,否則將追究法律責任。

相關文章