<input type="hidden" id="_wpnonce" name="_wpnonce" value="41c53f01ae" /><input type="hidden" name="_wp_http_referer" value="/blog/wp-json/wp/v2/posts/28150" /><input type="hidden" id="_wpnonce" name="_wpnonce" value="41c53f01ae" /><input type="hidden" name="_wp_http_referer" value="/blog/wp-json/wp/v2/posts/28150" />{"id":28150,"date":"2019-12-11T11:02:32","date_gmt":"2019-12-11T00:02:32","guid":{"rendered":"https:\/\/www.businesslegions.com\/blog\/?p=28150"},"modified":"2019-12-09T11:03:10","modified_gmt":"2019-12-09T00:03:10","slug":"script-to-backup-all-mysql-databases-in-vestacp","status":"publish","type":"post","link":"https:\/\/www.businesslegions.com\/blog\/2019\/12\/11\/script-to-backup-all-mysql-databases-in-vestacp\/","title":{"rendered":"SCRIPT TO BACKUP ALL MYSQL DATABASES IN VESTACP"},"content":{"rendered":"<!--CusAds0--><p>If you have multiple databases hosted on VestaCP the easiest way I found to backup all the databases is to use a script. The first thing you need to do is create a backup account in mySQL that has view only access to all the databases.<\/p>\n<pre class=\"ql-syntax\" spellcheck=\"false\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">USER<\/span> <span class=\"hljs-string\">'backupuser'<\/span>@<span class=\"hljs-string\">'localhost'<\/span>\r\n    <span class=\"hljs-keyword\">IDENTIFIED<\/span> <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-string\">'xxx'<\/span>;\r\n<\/pre>\n<pre class=\"ql-syntax\" spellcheck=\"false\"><span class=\"hljs-keyword\">GRANT<\/span> <span class=\"hljs-keyword\">SELECT<\/span>, <span class=\"hljs-keyword\">SHOW<\/span> <span class=\"hljs-keyword\">VIEW<\/span>, <span class=\"hljs-keyword\">LOCK<\/span> <span class=\"hljs-keyword\">TABLES<\/span>, RELOAD,\r\n    <span class=\"hljs-keyword\">REPLICATION<\/span> <span class=\"hljs-keyword\">CLIENT<\/span>\r\n    <span class=\"hljs-keyword\">ON<\/span> *.* <span class=\"hljs-keyword\">TO<\/span> <span class=\"hljs-string\">'backupuser'<\/span>@<span class=\"hljs-string\">'localhost'<\/span>;\r\n<\/pre>\n<pre class=\"ql-syntax\" spellcheck=\"false\"><span class=\"hljs-keyword\">FLUSH<\/span> <span class=\"hljs-keyword\">PRIVILEGES<\/span>;<\/pre>\n<p>Then use this bash script. You can change the variables accordingly but the most important is the backup location, username and password which was created above:<\/p><!--CusAds0-->\n<p>#! \/bin\/bash<\/p>\n<p>TIMESTAMP=$(date +&#8221;%F&#8221;)<br \/>\nBACKUP_DIR=&#8221;\/web\/backup\/$TIMESTAMP&#8221;<br \/>\nMYSQL_USER=&#8221;xxx&#8221;<br \/>\nMYSQL=\/usr\/bin\/mysql<br \/>\nMYSQL_PASSWORD=&#8221;xxx&#8221;<br \/>\nMYSQLDUMP=\/usr\/bin\/mysqldump<\/p>\n<p>mkdir -p &#8220;$BACKUP_DIR\/mysql&#8221;<\/p>\n<p>databases=`$MYSQL &#8211;user=$MYSQL_USER -p$MYSQL_PASSWORD -e &#8220;SHOW DATABASES;&#8221; | grep -Ev &#8220;(Database|information_schema|performance_schema)&#8221;`<\/p>\n<p>for db in $databases; do<br \/>\n$MYSQLDUMP &#8211;force &#8211;opt &#8211;user=$MYSQL_USER -p$MYSQL_PASSWORD &#8211;databases $db | gzip &gt; &#8220;$BACKUP_DIR\/mysql\/$db.gz&#8221;<br \/>\ndone<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-28184 size-full\" src=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2019\/12\/Business-Legions-SCRIPT-TO-BACKUP-ALL-MYSQL-DATABASES-IN-VESTACP.png?strip=all\" alt=\"Business Legions - SCRIPT TO BACKUP ALL MYSQL DATABASES IN VESTACP\" width=\"1195\" height=\"377\" srcset=\"https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2019\/12\/Business-Legions-SCRIPT-TO-BACKUP-ALL-MYSQL-DATABASES-IN-VESTACP.png?strip=all 1195w, https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2019\/12\/Business-Legions-SCRIPT-TO-BACKUP-ALL-MYSQL-DATABASES-IN-VESTACP-300x95.png?strip=all 300w, https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2019\/12\/Business-Legions-SCRIPT-TO-BACKUP-ALL-MYSQL-DATABASES-IN-VESTACP-768x242.png?strip=all 768w, https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2019\/12\/Business-Legions-SCRIPT-TO-BACKUP-ALL-MYSQL-DATABASES-IN-VESTACP-178x56.png?strip=all 178w, https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2019\/12\/Business-Legions-SCRIPT-TO-BACKUP-ALL-MYSQL-DATABASES-IN-VESTACP.png?strip=all&amp;w=239 239w, https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2019\/12\/Business-Legions-SCRIPT-TO-BACKUP-ALL-MYSQL-DATABASES-IN-VESTACP.png?strip=all&amp;w=478 478w, https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2019\/12\/Business-Legions-SCRIPT-TO-BACKUP-ALL-MYSQL-DATABASES-IN-VESTACP.png?strip=all&amp;w=717 717w, https:\/\/cdn.businesslegions.com\/blog\/wp-content\/uploads\/2019\/12\/Business-Legions-SCRIPT-TO-BACKUP-ALL-MYSQL-DATABASES-IN-VESTACP.png?strip=all&amp;w=956 956w\" sizes=\"(max-width: 960px) 100vw, 960px\" \/><\/p>\n<p>Hopefully, this has helped someone.<\/p>\n<div class=\"lt-box\" style=\"border:1px solid #1d6a9e\"><div class=\"lt-box-title\" style=\"background-color:#2485C6;border-top:1px solid #a7cee8;text-shadow:1px 1px 0 #0b283b\">DO YOU LIKE WHAT YOU'VE READ?<\/div><div class=\"lt-box-content\">Join our subscription list and receive our content right in your mailbox. If you like to receive some Great deals our Freebies then subscribe now!\r\n\r\n<p><div class=\"tnp tnp-subscription \">\n<form method=\"post\" action=\"https:\/\/www.businesslegions.com\/blog\/wp-admin\/admin-ajax.php?action=tnp&amp;na=s\">\n<input type=\"hidden\" name=\"nlang\" value=\"\">\n<div class=\"tnp-field tnp-field-firstname\"><label for=\"tnp-1\">Name<\/label>\n<input class=\"tnp-name\" type=\"text\" name=\"nn\" id=\"tnp-1\" value=\"\" placeholder=\"\"><\/div>\n<div class=\"tnp-field tnp-field-email\"><label for=\"tnp-2\">Email<\/label>\n<input class=\"tnp-email\" type=\"email\" name=\"ne\" id=\"tnp-2\" value=\"\" placeholder=\"\" required><\/div>\n<div class=\"tnp-field tnp-field-button\" style=\"text-align: left\"><input class=\"tnp-submit\" type=\"submit\" value=\"Subscribe\" style=\"\">\n<\/div>\n<\/form>\n<\/div>\n<\/p>\r\n\r\n<\/div><\/div><!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>If you have multiple databases hosted on VestaCP the easiest way I found to backup all the databases is to use a script. The first thing you need to do is create a backup account in mySQL that has view only access to all the databases. CREATE USER &#8216;backupuser&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;xxx&#8217;; GRANT SELECT, SHOW [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":28186,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[616,497,1564,747,1653,479,1968,393],"class_list":["post-28150","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-business","tag-backup","tag-database","tag-databases","tag-mysql","tag-mysqldump","tag-script","tag-vestacp","tag-zip"],"_links":{"self":[{"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/posts\/28150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/comments?post=28150"}],"version-history":[{"count":3,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/posts\/28150\/revisions"}],"predecessor-version":[{"id":28185,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/posts\/28150\/revisions\/28185"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/media\/28186"}],"wp:attachment":[{"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/media?parent=28150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/categories?post=28150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.businesslegions.com\/blog\/wp-json\/wp\/v2\/tags?post=28150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}