{"id":1446,"date":"2014-05-30T09:35:16","date_gmt":"2014-05-30T01:35:16","guid":{"rendered":"http:\/\/blog.emhct.net.cn\/?p=1446"},"modified":"2014-11-13T14:03:12","modified_gmt":"2014-11-13T06:03:12","slug":"%e3%80%90debian7%e3%80%91%e6%8c%89%e9%9c%80%e5%a4%87%e4%bb%bd%e6%95%b0%e6%8d%ae%ef%bc%88mysql%ef%bc%89%ef%bc%8c%e5%b9%b6%e5%b0%86%e5%a4%87%e4%bb%bd%e5%a5%bd%e7%9a%84%e6%96%87%e4%bb%b6%e9%80%9a","status":"publish","type":"post","link":"http:\/\/myblog.emhct.net.cn\/index.php\/archives\/1446","title":{"rendered":"\u3010debian7\u3011\u6309\u9700\u5907\u4efd\u6570\u636e\uff08mysql\uff09\uff0c\u5e76\u5c06\u5907\u4efd\u597d\u7684\u6587\u4ef6\u901a\u8fc7\u90ae\u4ef6\u53d1\u9001\u5230\u6307\u5b9a\u90ae\u7bb1"},"content":{"rendered":"<p>\u9996\u5148\u9700\u8981\u5b89\u88c5\u8fd9\u51e0\u4e2a\u5305\uff1a<br \/>\nmutt\u3001uuencode\u3001sendmail<\/p>\n<p>\u811a\u672c\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n\r\n#need 2 var\r\nif (($# != 2)); then\r\n        echo &quot;need input &#x5B;DBNamefile] &#x5B;mode]&quot;\r\n        echo &quot;mode -&gt; 0, test DBNamefile read!&quot;\r\n        echo &quot;mode -&gt; 1, do DB bak!&quot;\r\n        exit;\r\nfi\r\n\r\nif (($2 &lt; 0 &amp;&amp; $2 &gt; 1)); then\r\n        echo &quot;err mode!&quot;\r\n        exit\r\nfi\r\n\r\n#filter some lines:\r\n# 1. pure tab line\r\n# 2. pure \\r\\n\r\n# 3. pure space line\r\nDBNameFilePath=$1\r\nsed \/^&#x5B;&#x5B;:space:]]*$\/d $DBNameFilePath &gt; $DBNameFilePath&quot;.tmp&quot;\r\n\r\n#pre-info\r\nloop_count=0\r\nbak_DBName_target=1\r\necho &quot;DBNameFilePath: &quot;$DBNameFilePath&quot; &lt;&lt;&lt;&gt;&gt;&gt; \u00a0DBNameFilePath_tmp: &quot;$DBNameFilePath&quot;.tmp&quot;\r\necho ============ output all db Name $(date +&quot;%Y%m%d&quot;)  ==================\r\nwhile read -r line\r\ndo\r\n    #echo $line\r\n        bak_DBName_target&#x5B;loop_count]=$line\r\n        ((loop_count++))\r\ndone &lt; $DBNameFilePath&quot;.tmp&quot;\r\n\r\ni=0\r\nfor ((;i&lt;$loop_count &amp;&amp; $loop_count&gt;0;i++))\r\ndo\r\n echo ${bak_DBName_target&#x5B;$i]}\r\ndone\r\necho &quot;total - &quot;$i\r\necho ============ end ==================\r\n\r\nif (($2 == 0)); then\r\n        echo &quot;test over&quot;\r\n        exit;\r\nfi\r\n\r\nif (($i&lt;=0)); then\r\n echo &quot;empty db name!&quot;\r\n exit\r\nfi\r\n\r\n#do work\r\ni=0\r\nfor ((;i&lt;$loop_count &amp;&amp; $loop_count&gt;0;i++))\r\ndo\r\n        DBName_Tmp=${bak_DBName_target&#x5B;$i]}\r\n        DataBakName_tmp=Data_bak_${DBName_Tmp}_$(date +&quot;%Y%m%d&quot;)\r\n\r\n        #del db before 3 days\r\n        rm -rf \/home\/backup\/Data_$(date -d -3day +&quot;%Y%m%d&quot;).tar.gz\r\n\r\n        #expory mysql db\r\n        mysqldump -u root -ppassword $DBName_Tmp &gt; \/tmp\/mysql_db_bak\/$DataBakName_tmp.sql\r\n\r\n        #compact db file\r\n        tar zcf \/tmp\/mysql_db_bak\/$DataBakName_tmp.tar.gz \/tmp\/mysql_db_bak\/$DataBakName_tmp.sql\r\n\r\n        #del temporary sql\r\n        rm -rf \/tmp\/mysql_db_bak\/$DataBakName_tmp.sql\r\n\r\n        #Send mail\r\n        mutt -s $DataBakName_tmp &quot;email@163.com&quot; -a \/tmp\/mysql_db_bak\/$DataBakName_tmp.tar.gz &lt; mailbody.txt\r\ndone\r\n\r\n<\/pre>\n<p>\u4e0a\u9762\u811a\u672c\u7684\u7528\u6cd5\u662f:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n.\/a.sh 1.txt 0\r\n<\/pre>\n<p>1.txt\u662f\u4fdd\u5b58\u8981\u5907\u4efd\u6570\u636e\u5e93\u540d\u79f0\u7684\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u9700\u8981\u5b89\u88c5\u8fd9\u51e0\u4e2a\u5305\uff1a mutt\u3001uuencode\u3001sendmail \u811a\u672c\u5982\u4e0b\uff1a #!\/bin\/bash #need 2 var if (($# != 2)); then echo &quot;need input &#x5B;DBNamefile] &#x5B;mode]&quot; echo &quot;mode  &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/myblog.emhct.net.cn\/index.php\/archives\/1446\">read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[57,55,58,56],"class_list":["post-1446","post","type-post","status-publish","format-standard","hentry","category-linux-shell","tag-debian7","tag-linux","tag-mysql","tag-shell_script"],"_links":{"self":[{"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/posts\/1446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1446"}],"version-history":[{"count":6,"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/posts\/1446\/revisions"}],"predecessor-version":[{"id":1490,"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/posts\/1446\/revisions\/1490"}],"wp:attachment":[{"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1446"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/myblog.emhct.net.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}