{"id":130,"date":"2024-02-25T16:45:46","date_gmt":"2024-02-25T08:45:46","guid":{"rendered":"http:\/\/esufy.com\/?p=130"},"modified":"2024-03-10T15:40:14","modified_gmt":"2024-03-10T07:40:14","slug":"%e4%b8%a4%e4%b8%aashell%e8%84%9a%e6%9c%ac%e6%90%9e%e5%ae%9a%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e4%bb%bb%e5%8a%a1","status":"publish","type":"post","link":"http:\/\/www.esufy.cn\/?p=130","title":{"rendered":"\u4e24\u4e2aShell\u811a\u672c\u641e\u5b9amysql\u6570\u636e\u5e93\u5907\u4efd\u4efb\u52a1"},"content":{"rendered":"<p>\u5728\u4fe1\u606f\u65f6\u4ee3\uff0c\u6570\u636e\u7684\u91cd\u8981\u6027\u65e5\u76ca\u51f8\u663e\u3002\u65e0\u8bba\u662f\u4e2a\u4eba\u7528\u6237\u8fd8\u662f\u4f01\u4e1a\u7528\u6237\uff0c\u6570\u636e\u5e93\u90fd\u627f\u8f7d\u7740\u81f3\u5173\u91cd\u8981\u7684\u4fe1\u606f\u3002\u7136\u800c\uff0c\u7531\u4e8e\u8f6f\u4ef6\u9519\u8bef\u3001\u786c\u4ef6\u6545\u969c\u3001\u7f51\u7edc\u653b\u51fb\u7b49\u5404\u79cd\u539f\u56e0\uff0c\u6570\u636e\u5e93\u53ef\u80fd\u4f1a\u51fa\u73b0\u95ee\u9898\u3002\u8fd9\u65f6\uff0c\u5907\u4efd\u7684\u91cd\u8981\u6027\u5c31\u4f53\u73b0\u51fa\u6765\u4e86\u3002\u6570\u636e\u5e93\u5907\u4efd\u53ef\u4ee5\u5728\u6570\u636e\u4e22\u5931\u6216\u635f\u574f\u65f6\u6062\u590d\u6570\u636e\uff0c\u4fdd\u62a4\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u53ef\u7528\u6027\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u8bf4\u660e\u6570\u636e\u5e93\u5907\u4efd\u7684\u91cd\u8981\u6027\u3002<\/p>\n<p><strong>\u6570\u636e\u4fdd\u62a4<\/strong><\/p>\n<p>\u6570\u636e\u5e93\u5907\u4efd\u662f\u4fdd\u62a4\u6570\u636e\u7684\u6700\u4f73\u624b\u6bb5\u4e4b\u4e00\u3002\u901a\u8fc7\u5b9a\u671f\u5907\u4efd\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u786e\u4fdd\u5728\u6570\u636e\u88ab\u7be1\u6539\u3001\u5220\u9664\u6216\u635f\u574f\u65f6\uff0c\u53ef\u4ee5\u6062\u590d\u5230\u5907\u4efd\u70b9\uff0c\u4fdd\u8bc1\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u53ef\u7528\u6027\u3002\u5982\u679c\u6ca1\u6709\u5907\u4efd\uff0c\u4e00\u65e6\u6570\u636e\u4e22\u5931\u6216\u635f\u574f\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u65e0\u6cd5\u633d\u56de\u7684\u540e\u679c\u3002<\/p>\n<p><strong>\u9632\u6b62\u6570\u636e\u4e22\u5931<\/strong><\/p>\n<p>\u6570\u636e\u5e93\u5907\u4efd\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62\u6570\u636e\u4e22\u5931\u3002\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u6570\u636e\u5e93\u7684\u8bfb\u5199\u64cd\u4f5c\u975e\u5e38\u9891\u7e41\uff0c\u5bb9\u6613\u5bfc\u81f4\u6570\u636e\u4e22\u5931\u6216\u635f\u574f\u3002\u901a\u8fc7\u5b9a\u671f\u5907\u4efd\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u786e\u4fdd\u5728\u6570\u636e\u4e22\u5931\u6216\u635f\u574f\u65f6\uff0c\u8fc5\u901f\u6062\u590d\u5230\u5907\u4efd\u70b9\uff0c\u4fdd\u8bc1\u4e1a\u52a1\u7684\u8fde\u7eed\u6027\u3002<\/p>\n<p><strong>\u6ee1\u8db3\u6cd5\u89c4\u8981\u6c42<\/strong><\/p>\n<p>\u5bf9\u4e8e\u4f01\u4e1a\u7528\u6237\u6765\u8bf4\uff0c\u6570\u636e\u5e93\u5907\u4efd\u662f\u6ee1\u8db3\u6cd5\u89c4\u8981\u6c42\u7684\u91cd\u8981\u624b\u6bb5\u4e4b\u4e00\u3002\u5728\u4e00\u4e9b\u884c\u4e1a\u4e2d\uff0c\u5982\u91d1\u878d\u3001\u533b\u7597\u7b49\uff0c\u6cd5\u89c4\u8981\u6c42\u4f01\u4e1a\u5fc5\u987b\u5bf9\u6570\u636e\u8fdb\u884c\u5907\u4efd\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u53ef\u7528\u6027\u3002\u901a\u8fc7\u6570\u636e\u5e93\u5907\u4efd\uff0c\u4f01\u4e1a\u53ef\u4ee5\u6ee1\u8db3\u8fd9\u4e9b\u6cd5\u89c4\u8981\u6c42\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6cd5\u5f8b\u98ce\u9669\u3002<\/p>\n<p><strong>\u63d0\u9ad8\u7cfb\u7edf\u6027\u80fd<\/strong><\/p>\n<p>\u6570\u636e\u5e93\u5907\u4efd\u53ef\u4ee5\u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\u3002\u5728\u8fdb\u884c\u6570\u636e\u5e93\u5907\u4efd\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5c06\u6570\u636e\u4ece\u78c1\u76d8\u8bfb\u5165\u5230\u5185\u5b58\u4e2d\uff0c\u7136\u540e\u5c06\u5176\u5199\u5165\u5230\u5907\u4efd\u6587\u4ef6\u4e2d\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u53ef\u4ee5\u52a0\u901f\u6570\u636e\u7684\u8bfb\u5199\u64cd\u4f5c\uff0c\u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\u3002\u6b64\u5916\uff0c\u5907\u4efd\u6570\u636e\u53ef\u4ee5\u91ca\u653e\u78c1\u76d8\u7a7a\u95f4\uff0c\u51cf\u5c11\u7cfb\u7edf\u7684\u8d1f\u8f7d\u3002<\/p>\n<p><strong>\u5bb9\u707e\u80fd\u529b<\/strong><\/p>\n<p>\u6570\u636e\u5e93\u5907\u4efd\u5177\u6709\u5bb9\u707e\u80fd\u529b\u3002\u5728\u53d1\u751f\u81ea\u7136\u707e\u5bb3\u3001\u706b\u707e\u7b49\u610f\u5916\u60c5\u51b5\u4e0b\uff0c\u5907\u4efd\u6570\u636e\u53ef\u4ee5\u4fdd\u62a4\u4f01\u4e1a\u7684\u6838\u5fc3\u6570\u636e\uff0c\u786e\u4fdd\u4e1a\u52a1\u7684\u8fde\u7eed\u6027\u3002\u901a\u8fc7\u5907\u4efd\u6570\u636e\u7684\u5feb\u901f\u6062\u590d\uff0c\u53ef\u4ee5\u51cf\u5c11\u4f01\u4e1a\u7684\u635f\u5931\u3002<\/p>\n<p><strong>\u793a\u4f8b<\/strong><br \/>\n<strong>\u5355\u5faa\u73af\u5907\u4efd\u811a\u672c\uff1a<\/strong><\/p>\n<p>#!\/bin\/bash<br \/>\nDATE=$(date +%F_%H-%M-%S)<br \/>\nHOST=localhost<br \/>\nUSER=backup<br \/>\nPASS=123.com<br \/>\nBACKUP_DIR=\/data\/db_backup<br \/>\nDB_LIST=$(mysql -h$HOST -u$USER -p$PASS -s -e &#8220;show databases;&#8221; 2&gt;\/dev\/null |egrep -v &#8220;Database|information_schema|mysql|performance_schema|sys&#8221;)<\/p>\n<p>for DB in $DB_LIST; do<br \/>\nBACKUP_NAME=$BACKUP_DIR\/${DB}_${DATE}.sql<br \/>\nif ! mysqldump -h$HOST -u$USER -p$PASS -B $DB &gt; $BACKUP_NAME 2&gt;\/dev\/null; then<br \/>\necho &#8220;$BACKUP_NAME \u5907\u4efd\u5931\u8d25!&#8221;<br \/>\nfi<br \/>\ndone<\/p>\n<p><strong>\u591a\u5faa\u73af\u5907\u4efd\u811a\u672c\uff1a<\/strong><\/p>\n<p>#!\/bin\/bash<br \/>\nDATE=$(date +%F_%H-%M-%S)<br \/>\nHOST=localhost<br \/>\nUSER=backup<br \/>\nPASS=123.com<br \/>\nBACKUP_DIR=\/data\/db_backup<br \/>\nDB_LIST=$(mysql -h$HOST -u$USER -p$PASS -s -e &#8220;show databases;&#8221; 2&gt;\/dev\/null |egrep -v &#8220;Database|information_schema|mysql|performance_schema|sys&#8221;)<\/p>\n<p>for DB in $DB_LIST; do<br \/>\nBACKUP_DB_DIR=$BACKUP_DIR\/${DB}_${DATE}<br \/>\n[ ! -d $BACKUP_DB_DIR ] &amp;&amp; mkdir -p $BACKUP_DB_DIR &amp;&gt;\/dev\/null<br \/>\nTABLE_LIST=$(mysql -h$HOST -u$USER -p$PASS -s -e &#8220;use $DB;show tables;&#8221; 2&gt;\/dev\/null)<br \/>\nfor TABLE in $TABLE_LIST; do<br \/>\nBACKUP_NAME=$BACKUP_DB_DIR\/${TABLE}.sql<br \/>\nif ! mysqldump -h$HOST -u$USER -p$PASS $DB $TABLE &gt; $BACKUP_NAME 2&gt;\/dev\/null; then<br \/>\necho &#8220;$BACKUP_NAME \u5907\u4efd\u5931\u8d25!&#8221;<br \/>\nfi<br \/>\ndone<br \/>\ndone<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4fe1\u606f\u65f6\u4ee3\uff0c\u6570\u636e\u7684\u91cd\u8981\u6027\u65e5\u76ca\u51f8\u663e\u3002\u65e0\u8bba\u662f\u4e2a\u4eba\u7528\u6237\u8fd8\u662f\u4f01\u4e1a\u7528\u6237\uff0c\u6570\u636e\u5e93\u90fd\u627f\u8f7d\u7740\u81f3\u5173\u91cd\u8981\u7684\u4fe1\u606f\u3002\u7136\u800c\uff0c\u7531\u4e8e\u8f6f\u4ef6\u9519\u8bef [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":304,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[25],"tags":[10],"_links":{"self":[{"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/posts\/130"}],"collection":[{"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=130"}],"version-history":[{"count":3,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":133,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/posts\/130\/revisions\/133"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=\/wp\/v2\/media\/304"}],"wp:attachment":[{"href":"http:\/\/www.esufy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.esufy.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}