中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

每天自動(dòng)備份mysql腳本

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
1、執(zhí)行
crontab -e
00 00 * * * /bin/bash yourpath/mysqlbak.sh
2、打開自動(dòng)執(zhí)行文件
vi /etc/crontab
在etc中加入如下內(nèi)容,讓其自動(dòng)執(zhí)行任務(wù)。
00 00 * * * root /mysqlbak.sh
以上兩個(gè) 00    00    *    *    *  為每天的凌晨自動(dòng)執(zhí)行腳本

分 時(shí) 日 月 周 命令

M: 分鐘(0-59)。每分鐘用*或者 */1表示
H:小時(shí)(0-23)。(0表示0點(diǎn))
D:天(1-31)。
m: 月(1-12)。
d: 一星期內(nèi)的天(0~6,0為星期天)。
每五分鐘執(zhí)行    */5 * * * *
每小時(shí)執(zhí)行      0 * * * *
每天執(zhí)行        0 0 * * *
每周執(zhí)行        0 0 * * 0
每月執(zhí)行        0 0 1 * *
每年執(zhí)行        0 0 1 1 *
重啟cron
/etc/rc.d/init.d/crond restart
or
service crond restart
詳細(xì)請(qǐng)看crond的wiki
http://zh.wikipedia.org/wiki/Cron
mysqlback.sh
#!/bin/bash
#功能說明:本功能用于備份數(shù)據(jù)庫
#編寫日期:2010/12/06
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin
export PATH
#數(shù)據(jù)庫用戶名
dbuser=’root’
#數(shù)據(jù)庫密碼
dbpasswd=’123456′
#數(shù)據(jù)庫名,可以定義多個(gè)數(shù)據(jù)庫,中間以空格隔開,如:test test1 test2
dbname=’test1 test2′
#備份時(shí)間
backtime=`date +%Y%m%d%H%M%S`
#日志備份路徑
logpath=’/second/backup’
#數(shù)據(jù)備份路徑
datapath=’/second/backup’
#日志記錄頭部
echo ‘”備份時(shí)間為${backtime},備份數(shù)據(jù)庫表 ${dbname} 開始” >> ${logpath}/mysqllog.log
#正式備份數(shù)據(jù)庫
for table in $dbname; do
source=`mysqldump -u ${dbuser} -p${dbpasswd} ${table}> ${logpath}/${backtime}.sql` 2>> ${logpath}/mysqllog.log;
#備份成功以下操作
if [ "$?" == 0 ];then
cd $datapath
#為節(jié)約硬盤空間,將數(shù)據(jù)庫壓縮
tar jcf ${table}${backtime}.tar.bz2 ${backtime}.sql > /dev/null
#刪除原始文件,只留壓縮后文件
rm -f ${datapath}/${backtime}.sql
echo “數(shù)據(jù)庫表 ${dbname} 備份成功!!” >> ${logpath}/mysqllog.log
else
#備份失敗則進(jìn)行以下操作
echo “數(shù)據(jù)庫表 ${dbname} 備份失敗!!” >> ${logpath}/mysqllog.log
fi
done

標(biāo)簽: Mysql 腳本 數(shù)據(jù)庫

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:一個(gè)很好用的js倒計(jì)時(shí)

下一篇:C# 計(jì)算文件SHA1值