{"id":7492,"date":"2018-05-29T10:42:10","date_gmt":"2018-05-29T02:42:10","guid":{"rendered":"http:\/\/rmohan.com\/?p=7492"},"modified":"2018-05-29T10:42:10","modified_gmt":"2018-05-29T02:42:10","slug":"mysql-backup-2","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7492","title":{"rendered":"Mysql backup"},"content":{"rendered":"<pre>#!\/usr\/bin\/env bash\r\n\r\nUSER=\"\"\r\nPASSWORD=\"\"\r\nOUTPUTDIR=\"\"\r\nDAYS_TO_KEEP=60\r\n\r\ndatabases=`mysql -u$USER -p$PASSWORD -e \"SHOW DATABASES;\" | tr -d \"| \" | grep -v Database`\r\ncd $OUTPUTDIR\r\nfor db in $databases; do\r\n    if [[ \"$db\" != \"information_schema\" ]] &amp;&amp; [[ \"$db\" != \"performance_schema\" ]] &amp;&amp; [[ \"$db\" != \"mysql\" ]] &amp;&amp; [[ \"$db\" != _* ]] ; then\r\n        echo \"Dumping database: $db\"\r\n        mysqldump -u mysqlbackup --databases --events $db | gzip &gt; `date +%Y%m%d`.$db.sql.gz\r\n    fi\r\ndone\r\nfind \u00a8$OUTPUTDIR*.gz\u00a8 -type f -ctime +$DAYS_TO_KEEP -exec rm '{}' ';'<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/env bash USER=&#8221;&#8221; PASSWORD=&#8221;&#8221; OUTPUTDIR=&#8221;&#8221; DAYS_TO_KEEP=60 databases=`mysql -u$USER -p$PASSWORD -e &#8220;SHOW DATABASES;&#8221; | tr -d &#8220;| &#8221; | grep -v Database` cd $OUTPUTDIR for db in $databases; do if [[ &#8220;$db&#8221; != &#8220;information_schema&#8221; ]] &amp;&amp; [[ &#8220;$db&#8221; != &#8220;performance_schema&#8221; ]] &amp;&amp; [[ &#8220;$db&#8221; != &#8220;mysql&#8221; ]] &amp;&amp; [[ &#8220;$db&#8221; != _* ]] ; then echo [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7492"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7492"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7492\/revisions"}],"predecessor-version":[{"id":7493,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7492\/revisions\/7493"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}