Easy tar-based backups to S3, with backup rotation, cleanup helpers, and pre-/post-backup hooks.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
s3-backup.gemspec

README.rdoc

s3-backup

Easy tar-based backups to S3, with backup rotation, cleanup helpers, and pre-/post-backup hooks.

Install

sudo gem install s3-backup

Easy Example

b = S3Backup.new('vps-backups')  # Init with the name of bucket to push to; keys handled by AWSCredentials

b.files << '/usr/local/important.data'
b.files << '/usr/local/more/important.data'
b.files << '/usr/local/secrets'

b.run

This will:

  1. Create a .tar.gz file including everything in files

  2. Push tar to S3

  3. Delete old backups (keeps 5 by default, but you can change copies_to_keep)

  4. Remove scratch files

Hooks

S3Backup also includes a before_backup and after_backup hook to take care of preparing dumpfiles and restarting services. These are just blocks of code.

Also useful, files_to_cleanup contains a list of files to cleanup post-backup. You can add your scratch files to this list and they'll be deleted after each run, even if an error is encountered.

tar_excludes is an array of patterns for tar to exclude – for example, “*.log”

For example:

b = S3Backup.new('vps-backups')

b.before_backup do
  `mysqldump -h locahost important_data > /tmp/important_data.sql`
  raise "mysqdump failed" if !$?.success?

  b.files_to_cleanup << '/tmp/important_data.sql'
  b.files << '/tmp/important_data.sql'
end

b.run

You'll find additional opts in the S3Backup docs.

Suggested deployment

Create a ruby script, and add to your crontab. Don't forget to 2>&1 the output and set a MAILTO to get error notices.

Notes

  1. This uses AWSCredentials to manage AWS keys.

  2. This doesn't work on Windows.

Copyright

Copyright © 2010 Ben Koski. See LICENSE for details.