Using Amazon S3 from the Command Line with s3sync

This post is part of a series on automatically backing up your website:

Installing s3sync

s3sync comes with two utilities: s3sync.rb, which can backup a directory to S3 rsync-style, and s3cmd.rb, which gives you a command-line interface to S3. We’re actually not going to use s3sync.rb to backup our files (in the next blog post I’ll show you how to use astrails-safe instead). However, we will be using the s3cmd.rb utility now in order to interact with S3 from the command line.

Since s3sync is a ruby gem, you install it like so:

sudo gem install s3sync

(I’m assuming you have full access to your Linux-based host and you’ve installed RubyGems.) Now we need to tell s3sync your Amazon S3 access key ID and your secret access key so that it can access your data. So create an s3config.yml file in one of the following directories:

$S3CONF/s3config.yml
$HOME/.s3conf/s3config.yml
/etc/s3conf/s3config.yml

and paste this inside your s3config.yml file:

AWS_ACCESS_KEY_ID: yourkeygoeshere
AWS_SECRET_ACCESS_KEY: yourkeygoeshere

and that’s it!

Using s3cmd

Now let’s test it out. Type the following at the Linux prompt:

s3cmd listbuckets

If the installation of s3sync went well, you should see a list of all of your buckets. Play around with these s3cmd commands to make sure everything is working well:

View the contents of a bucket s3cmd list BucketName
Retrieve a file from a bucket s3cmd get BucketName:TheFileOnS3.txt ALocalFile.txt
Add a file to a bucket s3cmd put BucketName:TheFileOnS3.txt ALocalFile.txt

Here is the full list of s3cmd commands.

Next Step: Backing Up Your Web Site

Now that you can access S3 from your web server, let’s actually back up your web site.

Continue to Part 3: Backing Up Your Data with Astrails-Safe »

You can leave a response, or trackback from your own site.

One Response to “Using Amazon S3 from the Command Line with s3sync”

  1. [...] s3sync, a Ruby gem that gives us a command line way to sync between my Mac and S3.  Here’s a great blog entry on the Ruby gem installation and config, so I won’t repeat that part.  Then, to backup your [...]

Leave a Reply