Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Simple ruby script to backup DB's, including backup rotation and moving backups to S3
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.



- Put in #{RAILS_ROOT}/lib

- If you're using S3 to store backups, puts your S3 credentials in /config/s3.yml

- Set the values for these constants:
 + S3 to true if you want backups moved to S3.
 + BACKUPS for the number of backups you want to save. Once this many have been archived, older ones are deleted for each new backup added. Set to 0 to save everything.
 + APP for the app name. Used by mysql and S3.

- Call with no arguments to back up entire db, or pass in table names as arguments to back up only those tables:
 ruby backup.rb
 ruby backup.rb table1 table2

- Restore thusly:
 gunzip < ~/2011-09-09-07_37_01.sql.gz | mysql -u root phu_production

- Cron this script for automated backups. Example crontab entries:

backup 'github' and 'twitter' tables every half hour, as root user, piping output to dev/null:
*/30 * * * * cd /apps/phu/current/lib && ruby backup.rb github twitter >> /dev/null 2>&1

backup entire db every 4 hours, ten minutes after the hour.
10 */4 * * * cd /apps/phu/current/lib && ruby backup.rb

backup entire db every night at 3am.
* 3 * * * root cd /apps/phu/current/lib && ruby backup.rb
Something went wrong with that request. Please try again.