一個簡單mysql 備份策略 。
#!/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 ~]#
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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL遠端備份策略舉例MySql
- MySQL中如何選擇合適的備份策略和備份工具MySql
- mysqlbinlog命令詳解 Part 9 MySQL備份策略MySql
- 刪除前一天的備份的一個簡單批處理
- 簡單的mysqldump備份(windows)MySqlWindows
- 備份保留策略
- H3C UniStor CB備份一體機:備份其實很簡單
- MYSQL定時備份(一)MySql
- ORACLE備份策略(轉)Oracle
- MySQL資料備份多種引數介紹及簡單示例MySql
- Mysql備份失敗案例(一)MySql
- ORACLE備份策略二(轉)Oracle
- 資料庫備份策略資料庫
- 【rman備份策略】實驗
- MySQL 遷移表空間,備份單表MySql
- 利用MySQL全備份(mysqldump),如何只恢復一個庫或者一個表?MySql
- mysql的冷備份與熱備份MySql
- MySQL:xtrabackup備份MySql
- Mysql備份系列MySql
- Java備份MySQLJavaMySql
- 【RMAN】RMAN的備份保留策略
- 初探MySQL資料備份及備份原理MySql
- Mysql備份與恢復(1)---物理備份MySql
- MySQL備份與主備配置MySql
- MySQL入門--備份與恢復(一)MySql
- MySQL:一個簡單insert語句的大概流程MySql
- 【MySQL】MySQL備份和恢復MySql
- mysql每日備份for LinuxMySqlLinux
- Mysql備份恢復MySql
- mysql備份指令碼MySql指令碼
- MySQL 定時備份MySql
- mysql5.5.20備份MySql
- MySQL資料備份MySql
- Mysql備份與恢復(2)---邏輯備份MySql
- MySQL 8:備份&匯入【備忘】MySql
- MySQL的冷備份和熱備份概念理解(轉)MySql
- Linux自動備份MySQLLinuxMySql
- mysql 資料庫 備份MySql資料庫
- Centos Mysql 主從備份CentOSMySql