{"id":22,"date":"2006-10-12T13:51:59","date_gmt":"2006-10-12T05:51:59","guid":{"rendered":"http:\/\/www\/zhouhonghe.com\/wordpress\/?p=22"},"modified":"2007-01-29T20:45:38","modified_gmt":"2007-01-29T12:45:38","slug":"%e4%b8%80%e4%b8%aamysql%e8%87%aa%e5%8a%a8%e5%a4%87%e4%bb%bd%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/blog.zhouhonghe.com\/?p=22","title":{"rendered":"\u4e00\u4e2aMysql\u81ea\u52a8\u5907\u4efd\u811a\u672c"},"content":{"rendered":"<p>\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u811a\u672c\u653e\u8fdbcrontab\uff0c\u6bcf\u5929\u51cc\u6668\u6267\u884c\u4e00\u6b21\uff0c\u81ea\u52a8\u5907\u4efd<\/p>\n<p>\u8fd9\u4e2a\u811a\u672c\u6bcf\u5929\u6700\u591a\u53ea\u6267\u884c\u4e00\u6b21\uff0c\u800c\u4e14\u53ea\u4fdd\u7559\u6700\u8fd1\u4e94\u5929\u7684\u5907\u4efd\u5728\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<p>\u4ee3\u7801:<\/p>\n<p>#!\/bin\/bash<br \/>\n#This is a ShellScript For Auto DB Backup<br \/>\n#Powered by aspbiz<br \/>\n#2004-09<\/p>\n<p>#Setting<br \/>\n#\u8bbe\u7f6e\u6570\u636e\u5e93\u540d\uff0c\u6570\u636e\u5e93\u767b\u5f55\u540d\uff0c\u5bc6\u7801\uff0c\u5907\u4efd\u8def\u5f84\uff0c\u65e5\u5fd7\u8def\u5f84\uff0c\u6570\u636e\u6587\u4ef6\u4f4d\u7f6e\uff0c\u4ee5\u53ca\u5907\u4efd\u65b9\u5f0f<br \/>\n#\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5907\u4efd\u65b9\u5f0f\u662ftar\uff0c\u8fd8\u53ef\u4ee5\u662fmysqldump,mysqldotcopy<br \/>\n#\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u7528root(\u7a7a)\u767b\u5f55mysql\u6570\u636e\u5e93\uff0c\u5907\u4efd\u81f3\/root\/dbxxxxx.tgz<br \/>\nDBName=mysql<br \/>\nDBUser=root<br \/>\nDBPasswd=<br \/>\nBackupPath=\/root\/<br \/>\nLogFile=\/root\/db.log<br \/>\nDBPath=\/var\/lib\/mysql\/<br \/>\n#BackupMethod=mysqldump<br \/>\n#BackupMethod=mysqlhotcopy<br \/>\n#BackupMethod=tar<br \/>\n#Setting End<br \/>\nNewFile=\"$BackupPath\"db$(date +%y%m%d).tgz<br \/>\nDumpFile=\"$BackupPath\"db$(date +%y%m%d)<br \/>\nOldFile=\"$BackupPath\"db$(date +%y%m%d --date='5 days ago').tgz<\/p>\n<p>echo \"-------------------------------------------\" &gt;&gt; $LogFile<br \/>\necho $(date +\"%y-%m-%d %H:%M:%S\") &gt;&gt; $LogFile<br \/>\necho \"--------------------------\" &gt;&gt; $LogFile<br \/>\n#Delete Old File<br \/>\nif [ -f $OldFile ]<br \/>\nthen<br \/>\nrm -f $OldFile &gt;&gt; $LogFile 2&gt;&amp;1<br \/>\necho \"[$OldFile]Delete Old File Success!\" &gt;&gt; $LogFile<br \/>\nelse<br \/>\necho \"[$OldFile]No Old Backup File!\" &gt;&gt; $LogFile<br \/>\nfi<\/p>\n<p>if [ -f $NewFile ]<br \/>\nthen<br \/>\necho \"[$NewFile]The Backup File is exists,Can't Backup!\" &gt;&gt; $LogFile<br \/>\nelse<br \/>\ncase $BackupMethod in<br \/>\nmysqldump)<br \/>\nif [ -z $DBPasswd ]<br \/>\nthen<br \/>\nmysqldump -u $DBUser --opt $DBName &gt; $DumpFile<br \/>\nelse<br \/>\nmysqldump -u $DBUser -p$DBPasswd --opt $DBName &gt; $DumpFile<br \/>\nfi<br \/>\ntar czvf $NewFile $DumpFile &gt;&gt; $LogFile 2&gt;&amp;1<br \/>\necho \"[$NewFile]Backup Success!\" &gt;&gt; $LogFile<br \/>\nrm -rf $DumpFile<br \/>\n;;<br \/>\nmysqlhotcopy)<br \/>\nrm -rf $DumpFile<br \/>\nmkdir $DumpFile<br \/>\nif [ -z $DBPasswd ]<br \/>\nthen<br \/>\nmysqlhotcopy -u $DBUser $DBName $DumpFile &gt;&gt; $LogFile 2&gt;&amp;1<br \/>\nelse<br \/>\nmysqlhotcopy -u $DBUser -p $DBPasswd $DBName $DumpFile &gt;&gt;$LogFile 2&gt;&amp;1<br \/>\nfi<br \/>\ntar czvf $NewFile $DumpFile &gt;&gt; $LogFile 2&gt;&amp;1<br \/>\necho \"[$NewFile]Backup Success!\" &gt;&gt; $LogFile<br \/>\nrm -rf $DumpFile<br \/>\n;;<br \/>\n*)<br \/>\n\/etc\/init.d\/mysqld stop &gt;\/dev\/null 2&gt;&amp;1<br \/>\ntar czvf $NewFile $DBPath$DBName &gt;&gt; $LogFile 2&gt;&amp;1<br \/>\n\/etc\/init.d\/mysqld start &gt;\/dev\/null 2&gt;&amp;1<br \/>\necho \"[$NewFile]Backup Success!\" &gt;&gt; $LogFile<br \/>\n;;<br \/>\nesac<br \/>\nfi<\/p>\n<p>echo \"-------------------------------------------\" &gt;&gt; $LogFile<\/p>\n<p>\u6765\u6e90\uff1a<a target=\"_blank\" href=\"http:\/\/bbs.chnbokee.com\/viewtopic.php?p=973\">http:\/\/bbs.chnbokee.com\/viewtopic.php?p=973<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u811a\u672c\u653e\u8fdbcrontab\uff0c\u6bcf\u5929\u51cc\u6668\u6267\u884c\u4e00\u6b21\uff0c\u81ea\u52a8\u5907\u4efd \u8fd9\u4e2a\u811a\u672c\u6bcf\u5929\u6700\u591a\u53ea\u6267\u884c\u4e00\u6b21\uff0c\u800c\u4e14\u53ea\u4fdd\u7559\u6700\u8fd1\u4e94\u5929\u7684 [&hellip;]<\/p>... ","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/blog.zhouhonghe.com\/index.php?rest_route=\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zhouhonghe.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zhouhonghe.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zhouhonghe.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zhouhonghe.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22"}],"version-history":[{"count":0,"href":"https:\/\/blog.zhouhonghe.com\/index.php?rest_route=\/wp\/v2\/posts\/22\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.zhouhonghe.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zhouhonghe.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zhouhonghe.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}