{"id":51,"date":"2014-11-16T22:45:16","date_gmt":"2014-11-16T22:45:16","guid":{"rendered":"http:\/\/chasberndt.com\/?p=51"},"modified":"2014-11-16T23:00:05","modified_gmt":"2014-11-16T23:00:05","slug":"database-backup-script","status":"publish","type":"post","link":"https:\/\/chasberndt.com\/?p=51","title":{"rendered":"Database Backup Script"},"content":{"rendered":"<p>I just wrote a little script to backup the database of this blog. This script is\u00a0<strong>absolutely not good for a production server<\/strong> and I do not warranty this to work correctly, but if you want something for backing up a DB this might not be a terrible way to start.<\/p>\n<p>I have this script setup in \/etc\/cron.daily\/ so it will run everyday at midnight. Keep in mind that the script <b>must be executable<\/b> for it to run.<\/p>\n<p><span style=\"text-decoration: underline;\">Script<\/span><\/p>\n<pre>#!\/bin\/bash\r\n# Backups WordPress database to the path defined below.\r\n# Variables.\r\nTIMESTAMP=$(date \"+%Y-%m-%d-%H%M\")\r\nFILENAME=$TIMESTAMP.sql\r\nFULLPATH=\/path\/to\/db\/exports\/\r\nDBUSER=username\r\nDBPASS=password\r\nDBSCHEMA=databasename\r\n# Setting working directory to FULLPATH provided above.\r\ncd $FULLPATH\r\n# Execute DB backup command.\r\nmysqldump -u $DBUSER -p$DBPASS $DBSCHEMA &gt; $FILENAME<\/pre>\n<p>If the script is deployed like mine is, it&#8217;s executed by root, so you shouldn&#8217;t have to worry about permissions issues. Again, just remember the script is executable by doing this:<\/p>\n<pre>chmod +x \/path\/to\/script.sh\r\n<\/pre>\n<p>Again, I don&#8217;t warranty this and it&#8217;s by no means a production quality script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just wrote a little script to backup the database of this blog. This script is\u00a0absolutely not good for a production server and I do not warranty this to work correctly, but if you want something for backing up a DB this might not be a terrible way to start. I have this script setup <a class=\"read-more\" href=\"https:\/\/chasberndt.com\/?p=51\">&hellip;&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-misc"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=51"}],"version-history":[{"count":6,"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":57,"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions\/57"}],"wp:attachment":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}