{"id":280,"date":"2020-11-16T18:51:29","date_gmt":"2020-11-16T18:51:29","guid":{"rendered":"https:\/\/tomtechproductions.be\/?p=280"},"modified":"2020-11-16T18:51:29","modified_gmt":"2020-11-16T18:51:29","slug":"backup-all-mysql-databases","status":"publish","type":"post","link":"https:\/\/blog.tomtechproductions.be\/index.php\/2020\/11\/16\/backup-all-mysql-databases\/","title":{"rendered":"Backup all mysql databases"},"content":{"rendered":"\n<p>I created an easy way to backup all mysql databases<br>\/mnt\/srv-ttp-nas\/ is a location on a local NAS<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\nsleep 10\n\nDB_USER=\"username\"\nDB_PASS=\"password\"\nBACKUP_DIR = \"\/mnt\/srv-ttp-nas\/bu\/databases\"\n\n#find all databasses and backup them\ndatabases=`mysql --user=$DB_USER --password=$DB_PASS -e \"SHOW DATABASES;\" | tr -d \"| \" | grep -v Database`\n\nfor db in $databases; do\n        echo \"Dumping database: $db\"\n        mysqldump $db -u $DB_USER -p --password=$DB_PASS | gzip > \"\/mnt\/srv-ttp-nas\/databases\/\"`date +%Y-%m-%d_%H-%M-%S`-$db.sql.gz\ndone\n\n#remove files older than one month\nfind \/mnt\/srv-ttp-nas\/databases\/* -mtime +31 -exec rm {} \\;<\/code><\/pre>\n\n\n\n<p>The power of this script is that if you add a new database this will automaticly be added.<\/p>\n\n\n\n<p><strong>Add to crontab to backup every 6 hours.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo crontab -e\n0 0,6,12,18 * * * \/home\/tom\/backup.sh<\/code><\/pre>\n\n\n\n<p>Preview of data on share<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"540\" src=\"https:\/\/tomtechproductions.be\/wp-content\/uploads\/2020\/11\/image-1024x540.png\" alt=\"\" class=\"wp-image-284\" srcset=\"https:\/\/blog.tomtechproductions.be\/wp-content\/uploads\/2020\/11\/image-1024x540.png 1024w, https:\/\/blog.tomtechproductions.be\/wp-content\/uploads\/2020\/11\/image-300x158.png 300w, https:\/\/blog.tomtechproductions.be\/wp-content\/uploads\/2020\/11\/image-768x405.png 768w, https:\/\/blog.tomtechproductions.be\/wp-content\/uploads\/2020\/11\/image.png 1244w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>I created an easy way to backup all mysql databases\/mnt\/srv-ttp-nas\/ is a location on a local NAS The power of this script is that if you add a new database this will automaticly be added. Add to crontab to backup every 6 hours. Preview of data on share<\/p>\n","protected":false},"author":1,"featured_media":286,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[21,22,29,31,38],"class_list":["post-280","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-geen-categorie","tag-database","tag-db","tag-linux","tag-mysql","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":0,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/media\/286"}],"wp:attachment":[{"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.tomtechproductions.be\/index.php\/wp-json\/wp\/v2\/tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}