{"id":68,"date":"2015-07-02T22:57:19","date_gmt":"2015-07-02T15:57:19","guid":{"rendered":"http:\/\/prosindo.com\/blog\/?p=68"},"modified":"2015-07-02T22:57:19","modified_gmt":"2015-07-02T15:57:19","slug":"auto-backup-mysql-ubuntu","status":"publish","type":"post","link":"https:\/\/prosindo.com\/blog\/2015\/07\/02\/auto-backup-mysql-ubuntu\/","title":{"rendered":"Auto Backup MySQL Ubuntu"},"content":{"rendered":"<p>#!\/bin\/bash<\/p>\n<p>#Options##############<br \/>\nBKFOLDER=&#8217;\/.backup\/db&#8217;<br \/>\nDBHOST=&#8217;localhost&#8217;<br \/>\nDBUSER=&#8217;db_user&#8217;<br \/>\nDBPW=&#8217;db_password&#8217;<br \/>\nDBNAME=(\u00a0 &#8216;dbname&#8217; )<br \/>\n#for all databases the user has access to, keep this uncommented:<br \/>\n#DBNAME=( `echo &#8220;show databases&#8221; |\u00a0 mysql &#8211;user=$DBUSER &#8211;password=$DBPW &#8211;host=$DBHOST\u00a0 | tail -n+3 `)<\/p>\n<p>#End Options #########<\/p>\n<p>echo &#8220;check if local .backups directory exists. if not create it&#8221;;<br \/>\nif [ ! -d &#8220;$BKFOLDER&#8221; ]; then<br \/>\nmkdir -p $BKFOLDER ;<br \/>\nfi<\/p>\n<p>echo &#8220;remove db files older than 6 day&#8221;;<br \/>\nfind $BKFOLDER\/*.tar.gz -type f -daystart -mtime +5 -exec rm {} \\;<\/p>\n<p>echo &#8220;get recent version of databases&#8221;;<br \/>\nfor i in &#8220;${DBNAME[@]}&#8221;<br \/>\ndo<br \/>\nFILENAME=$BKFOLDER\/$i-`date +\\%Y\\%m\\%d-\\%H\\%M\\%S`.sql<br \/>\nmysqldump &#8211;opt &#8211;user=$DBUSER &#8211;password=$DBPW &#8211;host=$DBHOST $i &#8211;lock-tables=false\u00a0\u00a0 &gt; $FILENAME<br \/>\ntar -zcvf $FILENAME.tar.gz $FILENAME<br \/>\nrm $FILENAME<br \/>\ndone<\/p>\n<p>echo &#8220;all done!&#8221;<\/p>\n<p>#cron<br \/>\n#0 0 * * * \/.backup\/backupmysql.sh<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/bash #Options############## BKFOLDER=&#8217;\/.backup\/db&#8217; DBHOST=&#8217;localhost&#8217; DBUSER=&#8217;db_user&#8217; DBPW=&#8217;db_password&#8217; DBNAME=(\u00a0 &#8216;dbname&#8217; ) #for all databases the user has access to, keep this uncommented: #DBNAME=( `echo &#8220;show databases&#8221; |\u00a0 mysql &#8211;user=$DBUSER &#8211;password=$DBPW &#8211;host=$DBHOST\u00a0 | tail -n+3 `) #End Options ######### echo &#8220;check if local .backups directory exists. if not create it&#8221;; if [ ! -d &#8220;$BKFOLDER&#8221; ]; then mkdir &hellip; <a href=\"https:\/\/prosindo.com\/blog\/2015\/07\/02\/auto-backup-mysql-ubuntu\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Auto Backup MySQL Ubuntu&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":0,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"wp:attachment":[{"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prosindo.com\/blog\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}