{"id":3610,"date":"2020-04-01T16:01:30","date_gmt":"2020-04-01T15:01:30","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=3610"},"modified":"2020-04-03T21:40:04","modified_gmt":"2020-04-03T20:40:04","slug":"mysql-backup-all-databases-in-separate-files","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/mysql-backup-all-databases-in-separate-files\/","title":{"rendered":"Mysql backup &#038; restore all databases in separate files"},"content":{"rendered":"\n<p><a href=\"https:\/\/gist.github.com\/andsens\/3736393\">https:\/\/gist.github.com\/andsens\/3736393<\/a><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\nuser=\"backup\"\npassword=\"s3cr3t\"\ndir=$(dirname $0)\"\/databases\"\nmysqldump=$(which mysqldump)\nmysql=$(which mysql)\ndatabases=`$mysql --user=$user --password=$password --batch --skip-column-names -e \"SHOW DATABASES;\" | grep -v 'mysql$\\|information_schema\\|performance_schema'`\n\nmkdir -p $dir\n\nfor database in $databases; do\n    $mysqldump \\\n        --user=$user --password=$password \\\n        --force \\\n        --quote-names --dump-date \\\n        --opt --single-transaction \\\n        --events --routines --triggers \\\n        --databases $database \\\n        --result-file=\"$dir\/$database.sql\"\ndone\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Restore<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\nhost=localhost\nuser=\"backup\"\npassword=\"s3cr3t\"\nmysql=$(which mysql)\nfiles=`ls databases_new\/*.sql`\n\nfor file in $files; do\n        echo \"Executing: $file\"\n        $mysql -h $host --user=$user --password=$password &lt; $file\ndone<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/gist.github.com\/andsens\/3736393 Restore<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3610","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=3610"}],"version-history":[{"count":5,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3610\/revisions"}],"predecessor-version":[{"id":3649,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3610\/revisions\/3649"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=3610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=3610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=3610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}