db_backups

A Command Line Interface to DB backups (using backup gem) stored in Rackspace CloudFiles

Designed for internal usage for our rails apps and their mysql backups, but could be driven in a more generic direction if anyone external was interested.

Setup:

Locomote only:
git clone [email protected]:locomote/config.git ~/.loco_config && ln -s ~/.loco_config/fogrc ~/.fog

or for everyone else:

echo "default:\n  rackspace_username: ${RACKSPACE_USERNAME}\n  rackspace_api_key: ${RACKSPACE_API_KEY}" > ~/.fog

Usage:

To load the latest production database to your local dev database:
bundle exec db_backups load
Loading backup <#DbBackup "foo.production.20130327023959.sql" size=245760> into database foo_development ... DONE
To list all the staging backups:
bundle exec db_backups -estaging index
+---------+---------------------------+----------------+
|              Db Backups (foo - staging)              |
+---------+---------------------------+----------------+
|         | last_modified             | content_length |
+---------+---------------------------+----------------+
| 0       | 2013-03-25 05:56:36 +1100 | 245760         |
| 1       | 2013-03-25 06:16:17 +1100 | 245760         |
| 2       | 2013-03-25 23:52:12 +1100 | 245760         |
| 3       | 2013-03-26 12:06:25 +1100 | 245760         |
| 4       | 2013-03-27 02:39:59 +1100 | 245760         |
+---------+---------------------------+----------------+
To get the backup "2" in the staging list:
bundle exec db_backups -estaging get 2

(NB. this cats the sql file. ie. handy for piping to another command, but if you want a copy of it use retreive ...)

To actually retrieve the backup "1" in the staging list:
bundle exec db_backups -estaging retrieve 1
Retrieving backup foo.staging.20130325061617.sql ... DONE

(ie. retrieve and save the backup file to disk)

To load the latest uat database into staging:
ssh foo-staging 'cd foo/current; APP_ENV=staging bundle exec db_backups -euat load'

(ie. make sure to set the APP_ENV env var correctly)

NB. The retrieve, get and load commands all take the index number as an argument, but default to the last one if no argument is given.