Fork me on GitHub

3 Steps to Synching A Directory to S3 in Centos 4 Linux

If you want a simple way to publish images and other media to the web using S3, the Ruby-based utility S3Sync works well. To run it in Centos 4, follow the steps below.
  1. Get S3Sync Get a current version of S3sync, unpack it, and give the scripts a home on your server.
  2. Upgrade/install Ruby if need be The standard Centos Ruby version gave me a strange error. I ended up adding the Collective Idea Yum repository to install an updated version of Ruby. The RPMs worked fine for me, but be sure to read the comments for caveats. To install via this repository, first edit /etc/yum.repos.d/ci.repo and insert the following text:
    name=[i] Collective Idea RPM Repository
    Then install via yum: yum install ruby
  3. Create a shell script encapsulating your S3Sync configuration I created my script with help from this article:
    export AWS_ACCESS_KEY_ID=<your access key>
    export AWS_SECRET_ACCESS_KEY=<your secret access key>
    # This file syncs a directory with a specified
    # bucket.
    BACKUPDIR=<directory of files you'd like synced to S3>
    SYNCDIR=<directory in which you put the s3sync scripts>
    S3BUCKET=<name of S3 bucket>
    S3PREFIX=<any prefix you'd like>
    # move to the scripts directory
    cd ${SYNCDIR}
    ./s3sync.rb -v -p -r ${BACKUPDIR} ${S3STORE}
    Note: If you receive any SSL related options, or wish to encrypt data being passed to S3, be sure to read s3sync's documentation.