{"id":1118,"date":"2005-07-29T19:27:25","date_gmt":"2005-07-29T10:27:25","guid":{"rendered":"http:\/\/unknowngenius.com\/blog\/?p=1118"},"modified":"2005-07-29T20:15:36","modified_gmt":"2005-07-29T11:15:36","slug":"automating-db-backups-pt-ii","status":"publish","type":"post","link":"https:\/\/unknowngenius.com\/blog\/archives\/2005\/07\/29\/automating-db-backups-pt-ii\/","title":{"rendered":"Automating DB Backups Pt. II"},"content":{"rendered":"<p>A quickie-techie follow-up to <a href=\"https:\/\/unknowngenius.com\/blog\/archives\/2005\/04\/21\/automating-db-backups-with-a-twist\/\">an old post<\/a> in which I exposed the simple, yet overlooked idea of having backups of your DB automatically sent to a gMail account.<\/p>\n<p><!--more--><br \/>\nI just had to implement that for a client, and did it without using neither cpanel nor a canned PHP script: this time, it&#8217;s all self-contained (provided you have a *nix server), so I thought I&#8217;d share. It&#8217;s actually even easier than before&#8230;<\/p>\n<p>All you need is access to your cron jobs (cpanel gives you that, otherwise ssh) and a way to upload a script to your server (either ftp or ssh).<\/p>\n<ol>\n<li>Create a new MySQL account for your backups. Give it SELECT privileges on all the DB you want to save, no other privs.<\/li>\n<li>Create another file (pico will do that for you if you are using ssh)  and insert the following commands:<br \/>\n<code>rm auto-db-backup.gz<br \/>\nmysqldump -u<b>db_backup_user<\/b> -p<b>db_backup_pwd<\/b> -B <b>db_to_save_1 db_to_save_2<\/b> | gzip > auto-db-backup.gz<br \/>\necho \"Automated DB backup\" | mutt -s \"Auto DB backup\" -a auto-db-backup.gz <b>your-address<\/b>@gmail.com<\/code><\/li>\n<li>Make your file executable by typing (assuming you have named it &#8216;auto-backup.sh&#8217;):<br \/>\n<code>chmod a+x auto-backup.sh<\/code><\/li>\n<li>Append the following line to your cronjobs file:<br \/>\n<code>08 01 * * * \/usr\/home\/<b>path-to-your-script<\/b>\/auto-backup.sh<\/code><br \/>\n(this line will send the backup every day at 1:08am, check out cron documentation for details).\n<\/li>\n<\/ol>\n<p>That should do it!<\/p>\n<p>Ok, time to get the hell out of the office&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A quickie-techie follow-up to an old post in which I exposed the simple, yet overlooked idea of having backups of your DB automatically sent to a gMail account.<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1118","post","type-post","status-publish","format-standard","hentry","category-geek"],"_links":{"self":[{"href":"https:\/\/unknowngenius.com\/blog\/wp-json\/wp\/v2\/posts\/1118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknowngenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknowngenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknowngenius.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/unknowngenius.com\/blog\/wp-json\/wp\/v2\/comments?post=1118"}],"version-history":[{"count":0,"href":"https:\/\/unknowngenius.com\/blog\/wp-json\/wp\/v2\/posts\/1118\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknowngenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknowngenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknowngenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}