亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

MySQL 備份

系統(tǒng) 3162 0

http://rimuhosting.com/howto/mysqlbackup.jsp

?

Automated MySQL Database Backup

Version 1

Want to backup your MySQL databases to another machine on a nightly basis??

Then create a /etc/cron.daily/mysqlbackup.sh job like this:

mysqldump? -- compress? - u?root? - p $pw ? - h? $currenthost ? -- add - drop - table? -- extended - insert? -- quote - names? -- databases?db1?db2 | ?mysql? - u?root? - p $pw ? - h? $remotehost

?

Run chmod +x /etc/cron.daily/mysqlbackup.sh .? And change the $ parameters to the appropriate 'real' values.

Or if you are not backing up to a separate host, run:

mysqldump? - u?root? - p $pw ? - h? $currenthost ? -- add - drop - table? -- extended - insert? -- quote - names? -- databases?db1?db2? > ? / var / log / mysql . backup . $(date? + " %Y%m%d " ) . sql?

?

Version 2

This one is slightly more advanced. It's a bash script that will basically do the same as above but also only keep a certain number of old copies.

Note that this script is prepared to backup as the root user, if you are going to be running this as a non root user you should modify paths to reflect that.

# !/bin/sh

#?List?of?databases?to?be?backed?up?separated?by?space

dblist = " db_name_1?db_name_2?db_name_3?etc. "

# ?Directory?for?backups
backupdir =/ root / mysql_dumps

# ?Number?of?versions?to?keep
numversions = 4

# ?Full?path?for?MySQL?hotcopy?command
#?Please?put?credentials?into?/root/.my.cnf
#hotcopycmd=/usr/bin/mysqlhotcopy

hotcopycmd = " /usr/bin/mysqldump?--lock-tables?--databases "

# ?Create?directory?if?needed
mkdir ? - p? " $backupdir "
if ?[? ! ? - d? " $backupdir " ?];?then
???echo?
" Invalid?directory:?$backupdir "
???
exit ? 1
fi

# ?Hotcopy?begins?here
echo? " Dumping?MySQL?Databases... "
RC
= 0
for ?database?in? $dblist ;? do
???echo
???echo?
" Dumping?$database?... "
???mv?
" $backupdir/$database.gz " ? " $backupdir/$database.0.gz " ? 2 > ? / dev / null
???
$hotcopycmd ? $database ? | ?gzip? > ? " $backupdir/$database.gz "

???RC
= $ ?
???
if ?[? $RC ? - gt? 0 ?];?then
?????
continue ;
???fi

???
# ?Rollover?the?backup?directories
???rm? - fr? " $backupdir/$database.$numversions.gz " ? 2 > ? / dev / null
???i
= $numversions
???
while ?[? $i ? - gt? 0 ?];? do
?????mv?
" $backupdir/$database.`expr?$i?-?1`.gz " ? " $backupdir/$database.$i.gz " ? 2 > ? / dev / null
?????i
= `expr? $i ? - ? 1 `
???done
done

if ?[? $RC ? - gt? 0 ?];?then
???echo?
" MySQL?Dump?failed! "
???
exit ? $RC
else
???
# ?Hotcopy?is?complete.?List?the?backup?versions!
???ls? - l? " $backupdir "
???echo?
" MySQL?Dump?is?complete! "
fi
exit ? 0

?

So this system has three parts. First is the file that holds the credentials, e.g. /root/.my.cnf and it's in standard mysql config format like so:

# ?cat?/root/.my.cnf??[client]?user=root?password=whatever?

?

Second is the script itself, as listed above. Enter the names of your dbs, how many copies to keep, and where to put them.

?

Third is the crontab entry that will run this script for you. For example, once per day:

# ?(Use?to?post?in?the?top?of?your?crontab)
#?-----------------?minute?(0?-?59)
#?|??--------------?hour?(0?-?23)
#?|??|??-----------?day?of?month?(1?-?31)
#?|??|??|??--------?month?(1?-?12)
#?|??|??|??|??-----?day?of?week?(0?-?7)?(Sunday=0?or?7)
#?|??|??|??|??|
#?*??*??*??*??*??command?to?be?executed


35 ? 01 ? * ? * ? * ? / root / mysql_backup . sh

?

?

完!

MySQL 備份


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 色噜噜五月综合激情久久爱 | 97在线免费视频观看 | 九九视频九九 | 日韩国产中文字幕 | 亚洲国产高清人在线 | 欧美人猛交日本人xxx | 久久久久久久综合 | 九九精品视频在线 | 伊人久久综合影院 | 日本免费中文字幕在线看 | 色偷偷青青草原在线视频 | 国产精品亚洲第一区二区三区 | 青草社区在线观看 | 国产在线一91区免费国产91 | 久久这里 | 四虎四虎1515hhcom | 亚洲国产高清视频 | 99热在线观看免费 | 在线观看国产精美视频 | 一区二区国产在线观看 | 国产人成精品免费视频 | 久久久久久久久久福利 | 国产中文字幕在线观看 | 国产资源站 | 久久99亚洲精品久久 | 九九国产在线观看 | 一级成人a毛片免费播放 | 国产在线精品一区二区三区 | a大片久久爱一级 | 久久国产综合精品欧美 | 中文字幕在线免费观看 | 操熟美女又肥又嫩的骚屁股 | 精品久久久久久久久免费影院 | se94se亚洲欧美在线 | 欧美激情 亚洲 | 噜噜色噜噜色 | 一级视频片 | 国产农村妇女毛片精品久久 | h在线免费视频 | www欧美视频 | 午夜私人影院在线观看 |