<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Perplexed Labs &#187; logs</title>
	<atom:link href="http://blog.perplexedlabs.com/tag/logs/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.perplexedlabs.com</link>
	<description>web development war stories from the frontlines to the backend</description>
	<lastBuildDate>Sat, 24 Jul 2010 16:27:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Automated Backups &#8211; A 5 Minute Script To Safer Data</title>
		<link>http://blog.perplexedlabs.com/2009/02/09/automated-backups-a-5-minute-script-to-safer-data/</link>
		<comments>http://blog.perplexedlabs.com/2009/02/09/automated-backups-a-5-minute-script-to-safer-data/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 20:16:24 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>

		<guid isPermaLink="false">http://www.perplexedlabs.com/?p=178</guid>
		<description><![CDATA[Sometimes, taking a few minutes to do a simple thing will save you a headache down the road.  Like changing the oil in your car, or brushing your teeth every night, or automatically backing up your databases. The development server that I mess around on has recently accumulated a lot of data that I really [...]


Related posts:<ol><li><a href='http://blog.perplexedlabs.com/2008/02/05/mysqldump-usage/' rel='bookmark' title='Permanent Link: mysqldump usage'>mysqldump usage</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/09/11/backing-up-subversion-repositories-using-svnadmin-hotcopy/' rel='bookmark' title='Permanent Link: Backing Up Subversion Repositories Using svnadmin hotcopy'>Backing Up Subversion Repositories Using svnadmin hotcopy</a></li>
<li><a href='http://blog.perplexedlabs.com/2008/02/04/building-a-rails-capable-slice-from-scratch/' rel='bookmark' title='Permanent Link: Ruby On Rails and SliceHost Part 1: Initial Setup'>Ruby On Rails and SliceHost Part 1: Initial Setup</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Sometimes, taking a few minutes to do a simple thing will save you a headache down the road.  Like changing the oil in your car, or brushing your teeth every night, or automatically backing up your databases.</p>
<p>The development server that I mess around on has recently accumulated a lot of data that I really don't want to lose, so I whipped up a small script that will help to ensure this never happens.</p>
<blockquote><p>#!/bin/bash<br />
rm -f /path/to/backups/tmp/*<br />
mysqldump --opt --host=localhost --user=USERNAME --password=PASSWORD --all-databases &gt; /path/to/backups/tmp/dbBackup.sql<br />
tar -czvf /path/to/backups/database/mysql.`date '+%Y%m%d%H%M%S'`.tar.gz /backups/tmp<br />
service httpd restart</p></blockquote>
<p>Line by line, what's happening here is:</p>
<ul>
<li>delete the .sql file generated by the previous backup</li>
<li>dump every MySQL table to a file called dbBackup.sql.  You don't have to go this far; check out <a href="http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html">MySQL's documentation on mysqldump</a> for all the options</li>
<li>tar up the dbBackup.sql file, include a timestamp in the filename</li>
<li>restart Apache</li>
</ul>
<p>I want this script to run every night at 1am, so I added it to the crontab:</p>
<blockquote><p>0 1 * * * /path/to/backup.daily.cron</p></blockquote>
<p>Obviously this is a very simple script that can grow in complexity fairly quickly.  For example, you can clear out old logs (a must for some Rails apps), and do other housekeeping functions.  A good idea would also be to have a syncing program grab that .tar and upload it to your home machine, or even an S3 bucket.</p>
<p>When your MySQL instance gets corrupted or otherwise obliterated, you'll thank yourself for taking 5 minutes to set this up.</p>


<p>Related posts:<ol><li><a href='http://blog.perplexedlabs.com/2008/02/05/mysqldump-usage/' rel='bookmark' title='Permanent Link: mysqldump usage'>mysqldump usage</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/09/11/backing-up-subversion-repositories-using-svnadmin-hotcopy/' rel='bookmark' title='Permanent Link: Backing Up Subversion Repositories Using svnadmin hotcopy'>Backing Up Subversion Repositories Using svnadmin hotcopy</a></li>
<li><a href='http://blog.perplexedlabs.com/2008/02/04/building-a-rails-capable-slice-from-scratch/' rel='bookmark' title='Permanent Link: Ruby On Rails and SliceHost Part 1: Initial Setup'>Ruby On Rails and SliceHost Part 1: Initial Setup</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.perplexedlabs.com/2009/02/09/automated-backups-a-5-minute-script-to-safer-data/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
