<?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>PHP Web developer, Robert Kern &#187; Amazon S3</title>
	<atom:link href="http://www.robertkern.com/tags/amazon-s3/feed" rel="self" type="application/rss+xml" />
	<link>http://www.robertkern.com</link>
	<description>Solid PHP Web Development with SEO and web standards in mind.</description>
	<lastBuildDate>Thu, 18 Mar 2010 20:05:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<cloud domain='www.robertkern.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Backup folders to Amazon S3 automatically</title>
		<link>http://www.robertkern.com/servers/backup-folders-to-amazon-automatically.html</link>
		<comments>http://www.robertkern.com/servers/backup-folders-to-amazon-automatically.html#comments</comments>
		<pubDate>Fri, 18 Dec 2009 21:50:40 +0000</pubDate>
		<dc:creator>Robert Kern</dc:creator>
				<category><![CDATA[Servers]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[Backup]]></category>

		<guid isPermaLink="false">http://www.robertkern.com/?p=494</guid>
		<description><![CDATA[After reading of Jeff Atwood&#8217;s data loss issues this past week I started thinking about the web servers I look after.  The servers are all backed up by the hosting provider &#8211; SiteHost &#8211; and I have a lot of faith in those backups (I work there, but I have also needed to restore some [...]


Related posts:<ol><li><a href='http://www.robertkern.com/software/is-backup-on-apple%e2%80%99s-back-burner-or-simply-abandoned.html' rel='bookmark' title='Permanent Link: Is Backup on Apple’s Back Burner or Simply Abandoned?'>Is Backup on Apple’s Back Burner or Simply Abandoned?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>After reading of <a href="http://www.codinghorror.com/blog/archives/001315.html">Jeff Atwood&#8217;s data loss issues</a> this past week I started thinking about the web servers I look after.  The servers are all backed up by the hosting provider &#8211; <a href="http://www.sitehost.co.nz">SiteHost</a> &#8211; and I have a lot of faith in those backups (I work there, but I have also needed to restore some data in the past and it was flawless), but that didnt stop me from thinking it would be a good idea to start doing backups <em><strong>that I control</strong></em>.<br />
I considered getting another VPS hosted in a separate data-centre and copying data over at frequent intervals (and I might do that at some stage so the traffic can be kept within NZ), but I already had an Amazon S3 account and use it for automated backups of the SVN repositories hosted with <a href="http://www.storehouseapp.com">Storehouse</a>.  So I wrote a little cli app (written in PHP) that tarballs, gzips, and copies the compressed folders up to S3.  The config file allows you to specify as many folders as you want and say whether you want them to be backed up daily, weekly, or monthly (these intervals can easily be changed and added to).</p>
<p>For detailed usage, keep reading.</p>
<p><span id="more-494"></span><a href="http://www.robertkern.com/downloads/s3_backup/s3_backup-r15.zip">Download the files</a> to your server (should run on anything that has a recent version of PHP).</p>
<p>Create a <span style="font-family: courier;">config.php</span> file in the <span style="font-family: courier;">./library</span> folder.</p>
<p>Any option that you see in the ./library/defaults.php file can be extended in the config.php file.  To get started, have a look at the following: (exchange the =&gt; for a greater-than sign =&gt; &#8211; whats the deal WP-Syntax?)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">'server_name'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'srv1.example.com'</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'folders'</span>     <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'all-websites'</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'dir'</span>       <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'/home/www'</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'frequency'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'daily'</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'mysql-backups'</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'dir'</span>       <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'/home/backup'</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'frequency'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'daily'</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'ssl-certs'</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'dir'</span>       <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'/root/ssl'</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'frequency'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'weekly'</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'amazon'</span>      <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'aws_key'</span>      <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'Your-AWS-Key'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'aws_secret'</span>  <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'Your-Secret-Key'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'s3_bucket'</span>   <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'Bucket-Name'</span><span style="color: #339933;">,</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then, you can simply setup a cron job to run the ./s3_backup/Run.php file each night when the server is less likely to be busy.</p>
<p>The first iteration of the app choked on large files because it was loading everything into memory, but this version streams the compressed data to S3 and in my tests it has never used more than 2MB memory (even with files of hundreds of MB).<br />
Right now, the app size is pretty hefty (6.3MB compressed) because it includes the whole Zend Framework library.</p>


<p>Related posts:<ol><li><a href='http://www.robertkern.com/software/is-backup-on-apple%e2%80%99s-back-burner-or-simply-abandoned.html' rel='bookmark' title='Permanent Link: Is Backup on Apple’s Back Burner or Simply Abandoned?'>Is Backup on Apple’s Back Burner or Simply Abandoned?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.robertkern.com/servers/backup-folders-to-amazon-automatically.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
