{"id":92,"date":"2020-09-15T11:03:31","date_gmt":"2020-09-15T03:03:31","guid":{"rendered":"http:\/\/blog.gamekingtao.top\/?p=92"},"modified":"2020-12-22T10:51:21","modified_gmt":"2020-12-22T02:51:21","slug":"mysql-%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/blog.gamekingtao.top\/index.php\/2020\/09\/15\/mysql-%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e8%84%9a%e6%9c%ac\/","title":{"rendered":"mysql  \u6570\u636e\u5e93\u5907\u4efd\u811a\u672c"},"content":{"rendered":"\n<h1>! \/bin\/bash<\/h1>\n\n\n\n<p>user=&#8221;\u8d26\u53f7&#8221;<br> userPWD=&#8221;\u5bc6\u7801&#8221;<\/p>\n\n\n\n<h1>#\u9700\u8981\u5b9a\u65f6\u5907\u4efd\u7684\u6570\u636e\u8868\u5217\u8868<\/h1>\n\n\n\n<p>dbNames=(\u6570\u636e\u5e93\u540d)<\/p>\n\n\n\n<h1>#\u6bcf\u6b21\u7684\u5907\u4efd\u6570\u636e\u4ee5\u65e5\u671f\u521b\u5efa\u6587\u4ef6\u5939\u5b58\u653e\uff0c\u540c\u65f6\u5220\u9664\u8fc7\u671f\u5907\u4efd<\/h1>\n\n\n\n<h1>#\u6b64\u5904\u4ee5\u4fdd\u75591\u4e2a\u6708\u7684\u5907\u4efd\u6570\u636e\u4e3a\u4f8b<\/h1>\n\n\n\n<p>DATE=<code>date -d \"now\" +%Y%m%d%H<\/code><br>\nODATE=<code>date -d \"-1 month\" +%Y%m%d%H<\/code><br>\nnewdir=\/data\/backup\/nm$DATE<br>\nolddir=\/data\/backup\/nm$ODATE<\/p>\n\n\n\n<h1>#\u5220\u9664\u8fc7\u671f\u5907\u4efd\u6570\u636e<\/h1>\n\n\n\n<p>if [ -d $olddir ];<br>\n  then<br>\n    rm -rf $olddir<br>\nfi<\/p>\n\n\n\n<h1>#\u521b\u5efa\u65b0\u5907\u4efd\u6587\u4ef6\u5939<\/h1>\n\n\n\n<p>mkdir $newdir<\/p>\n\n\n\n<h1>#\u5bf9\u5907\u4efd\u6570\u636e\u5e93\u5217\u8868\u7684\u6240\u6709\u6570\u636e\u5e93\u5907\u4efd<\/h1>\n\n\n\n<p>for dbName in ${dbNames[*]}<br> do<br>   dumpFile=$dbName-$DATE.sql.gz<br>   mysqldump -u$user -p$userPWD $dbName | gzip > $newdir\/$dumpFile<br> done<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>#! \/bin\/bash<br><\/strong><strong><br><\/strong>user=\"root\"<br>userPWD=\"zcy2020**\"<br>port=\"8441\"<br># \u9700\u8981\u5b9a\u65f6\u5907\u4efd\u7684\u6570\u636e\u8868\u5217\u8868<br>dbNames=(fd-online)<br># \u6bcf\u6b21\u7684\u5907\u4efd\u6570\u636e\u4ee5\u65e5\u671f\u521b\u5efa\u6587\u4ef6\u5939\u5b58\u653e\uff0c\u540c\u65f6\u5220\u9664\u8fc7\u671f\u5907\u4efd<br># \u6b64\u5904\u4ee5\u4fdd\u75591\u4e2a\u6708\u7684\u5907\u4efd\u6570\u636e\u4e3a\u4f8b<br>DATE=<em>`date <\/em>-d \"now\" +%Y%m%d%H<em>`<br><\/em>ODATE=<em>`date <\/em>-d \"-1 month\" +%Y%m%d%H<em>`<br><\/em>newdir=\/opt\/backup\/fd-online$DATE<br>olddir=\/opt\/backup\/fd-online$ODATE<br># \u5220\u9664\u8fc7\u671f\u5907\u4efd\u6570\u636e<br>if [ -d $olddir ];<br>  then<br>    <em>rm <\/em>-rf $olddir<br>fi<br># \u521b\u5efa\u65b0\u5907\u4efd\u6587\u4ef6\u5939<br><em>mkdir <\/em>$newdir<br># \u5bf9\u5907\u4efd\u6570\u636e\u5e93\u5217\u8868\u7684\u6240\u6709\u6570\u636e\u5e93\u5907\u4efd<br>for dbName in ${dbNames[*]}<br>do<br>  dumpFile=$dbName-$DATE.sql.gz<br>  <em>\/opt\/lampp\/bin\/mysqldump <\/em>-u$user -p$userPWD -P$port $dbName | <em>gzip <\/em>&gt; $newdir\/$dumpFile<br>done<br><br><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>! \/bin\/bash user=&#8221;\u8d26\u53f7&#8221; userPWD=&#8221;\u5bc6\u7801&#038;#82 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.gamekingtao.top\/index.php\/2020\/09\/15\/mysql-%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e8%84%9a%e6%9c%ac\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cmysql  \u6570\u636e\u5e93\u5907\u4efd\u811a\u672c\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/posts\/92"}],"collection":[{"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":3,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/posts\/92\/revisions\/119"}],"wp:attachment":[{"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}