Easy tar-based backups to S3, with backup rotation, cleanup helpers, and pre-/post-backup hooks.
sudo gem install s3-backup
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
Create a .tar.gz file including everything in files
Push tar to S3
Delete old backups (keeps 5 by default, but you can change copies_to_keep)
Remove scratch files
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”
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.
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.
This uses AWSCredentials to manage AWS keys.
This doesn't work on Windows.
Copyright © 2010 Ben Koski. See LICENSE for details.