S3DbAssetsBackup

Generates rake tasks for backing up and restoring your database and public folder (which should also contain any uploaded assets) to and from an existing bucket in your Amazon S3 account. The rake tasks compresses and uploads each backup with a time stamp and the config file allows you to set how many of each backup to keep. Additionally, the plugin can be configured to generate and send a backup status report via email.

Install

Edit your Gemfile to include

gem "s3_db_assets_backup"

Then run

bundle install

Create the config file.

rails g s3_backup

Edit config/s3_backup_config.yml with your aws credentials and email settings

Rails 2.x (switch to the rails_2.x branch)

Usage

Backup the production database.

rake db:backup RAILS_ENV=production

Restore the production database (you will be prompted to select an existing backup)

rake db:restore RAILS_ENV=production

Backup the public folder

rake assets:backup

Restore the public folder (you will be prompted to select an existing backup)

rake assets:restore

Send a backup status report to the configured email address

rake db:backup:status

Scheduling with whenever

Optionally, you can use “whenever” to automate backups and status reports.

Add whenever to your Gemfile

gem 'whenever', :require => false

To create the whenever config file, run the following command from the app root directory.

wheneverize .

Edit config/schedule.rb to schedule the rake tasks.

every 12.hours do
  rake "db:backup"
end

every 4.days do
  rake "db:backup:status"
end

Then run the following command to write the config to your cron file

whenever -w

For more information on the whenever gem, visit github.com/javan/whenever

Troubleshooting and FAQs

I get “cannot create ./tmp/production_dump-YYYY-MM-DD-HH-MM-SS.sql.gz: Directory nonexistent” when running the database backup to S3

You need to create a tmp directory in the project root.

mkdir tmp

My crontab doesn’t run in development.

Deving on a mac? Cron is deprecated in Mountain Lion.

Found a bug?

If you are having a problem with the plugin, first look at the FAQs above. If you still cannot resolve it, please submit an issue here.

github.com/randomutterings/s3_db_assets_backup/issues