http://jay.gooby.org/tag/s3 Posts tagged with "s3" - Jay Caines-Gooby 2010-02-10T13:36:05+00:00 Jay Caines-Gooby jay@gooby.org http://jay.gooby.org/ http://jay.gooby.org/post/versioning-your-amazon-s3-buckets Versioning your Amazon S3 buckets 2010-02-10T13:36:05+00:00 2010-02-10T13:39:56+00:00 <p><img src="/media/logo_aws.gif"/></p> <p>I&#8217;m sold <a href="http://groups.google.com/group/brightonnewmedia/msg/79f574c7cb488d63">hook</a> <a href="http://groups.google.com/group/brightonnewmedia/browse_thread/thread/9d9da90d21cfbb61">line</a> and <a href="http://groups.google.com/group/brightonnewmedia/browse_thread/thread/c24609d86278421a/">sinker</a> on the <span class="caps">AWS</span> platform. I&#8217;m especially impressed at the product innovation and ever-reducing prices.</p> <p>A few days ago Amazon announced <a href="http://aws.amazon.com/about-aws/whats-new/2010/02/08/versioning-feature-for-amazon-s3-now-available/">versioning for S3</a>. This means that with the versioning flag for a bucket switched on, you can retrieve earlier versions of your files. Sweet.</p> <p>Now, because I&#8217;m lazy, I tend to use <a href="http://www.s3fox.net/">S3Fox</a> or <a href="http://cyberduck.ch/">Cyberduck</a> for setting ACLs and creating european buckets and so on.</p> <p>Neither of these have updated yet to support the versioning flag, and the <a href="http://aws.amazon.com/console/"><span class="caps">AWS</span> Console</a> doesn&#8217;t have an S3 interface, so I thought I&#8217;d get my hands dirty and find out how to do it with the <a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/EnablingVersioning.html"><span class="caps">REST</span> interface</a>.</p> <p>You issue a <span class="caps">PUT</span> to your bucket with the versioning querystring and the relevant <span class="caps">XML</span>:</p> <pre name="code" class="xml:nogutter"> &lt;VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"&gt; &lt;Status&gt;Enabled&lt;/Status&gt; &lt;/VersioningConfiguration&gt; </pre> <p>You can do it all with <a href="http://curl.haxx.se/">cURL</a>, but the biggest pain is <a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html">generating the correct Authorization: header</a> to sign your <span class="caps">API</span> call.</p> <p>Enter Tim Kay&#8217;s <a href="http://timkay.com/aws/">aws commandline tool</a> &#8211; its a swiss knife for S3 and EC2 calls. Enabling the versioning was as simple as:</p> <pre name="code" class="bash:nogutter"> aws put my.bucket.com?versioning versioning.xml </pre> <p>Where versioning.xml contains the VersioningConfiguration xml snippet listed above.</p> <p>To check the versioning status of a bucket, you do:</p> <pre name="code" class="bash:nogutter"> aws get my.bucket.com?versioning </pre> <p>Before you run the aws commandline, you&#8217;ll need to create an ~/.awssecret file with your <span class="caps">AWS</span> key and secret key. Don&#8217;t forget to chmod 600.</p>