{"id":59,"date":"2006-09-30T13:20:10","date_gmt":"2006-09-30T12:20:10","guid":{"rendered":"http:\/\/www.hlynes.com\/2006\/09\/30\/backups-part-1-mysql\/"},"modified":"2006-09-30T13:31:28","modified_gmt":"2006-09-30T12:31:28","slug":"backups-part-1-mysql","status":"publish","type":"post","link":"http:\/\/www.hlynes.com\/?p=59","title":{"rendered":"Backups &#8211; Part 1: MySQL"},"content":{"rendered":"<p>Like most people I&#8217;ve got a number of MySQL servers with different databases running things like Wikis and other web-apps. MySQL ships with a handy little tool called <a href=\"http:\/\/www.mysql.org\/doc\/refman\/4.1\/en\/mysqldump.html\">mysqldump<\/a> which can be used to dump ( as the name suggests ) a mysql DB to a text file containing SQL commands necessary to re-create it.<\/p>\n<p>The first thing I like to do is to create a backup user that only has enough privileges to do the backup.<\/p>\n<pre>GRANT LOCK TABLES,SELECT,RELOAD,SHOW DATABASES ON *.* TO 'backup'@'localhost' IDENTIFIED BY 'mypasswd';\r\nFLUSH PRIVILEGES;<\/pre>\n<p>with this done you should be able to do something like<\/p>\n<pre>mysqldump -hlocalhost -ubackup -pmypasswd --databases mysql > test_backup.mysql<\/pre>\n<p>With that in place it was an easy task to write a <a href=\"http:\/\/popov-cs.grid.cf.ac.uk\/subversion\/WeSC\/scripts\/mysql_backup\">script<\/a> that can read a config file for the backup login info and options to pass to mysqldump. This script has a number of benefits over sticking a mysqldump command straight into cron:<\/p>\n<ol>\n<li>It stores it&#8217;s settings in an external config file so you can use the same script in several settings<\/li>\n<li>It backs up each database on the server into a separate dump file.<\/li>\n<li>The backup options are in the config file so you can back up different servers with different tweaks. e.g locking the DB for consistancy.<\/li>\n<\/ol>\n<p>the line in the config file looks like<\/p>\n<pre>localhost:backup:mypasswd:--opt --add-drop-table<\/pre>\n<p>I add a quick script to \/etc\/cron.daily like<\/p>\n<pre>mysql_backup -b \/var\/backups\/mysql -f \/etc\/mysql_backup<\/pre>\n<p>I can now sleep a bit easier. This isn&#8217;t the only way to back up mysql, proper DBAs will know all about replication and various other tricks.<\/p>\n<p>Next time: subversion repositories.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Like most people I&#8217;ve got a number of MySQL servers with different databases running things like Wikis and other web-apps. MySQL ships with a handy little tool called mysqldump which can be used to dump ( as the name suggests ) a mysql DB to a text file containing SQL commands necessary to re-create it. &hellip; <a href=\"http:\/\/www.hlynes.com\/?p=59\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Backups &#8211; Part 1: MySQL<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-sysadmin"],"_links":{"self":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/posts\/59"}],"collection":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=59"}],"version-history":[{"count":0,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/posts\/59\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}