Backup is a RubyGem, written for Linux and Mac OSX, that allows you to easily perform backup operations on both your remote, as well as your local environment. It provides you with an elegant DSL in Ruby for modeling (configuring) your backups. Backup has built-in support for various databases, storage protocols/services, syncers, compressors, encryptors and notifiers which you can mix and match. It was built with modularity, extensibility and simplicity in mind.
Michael van Rooijen ( @meskyanichi )
Drop me a message for any questions, suggestions, requests, bugs or submit them to the issue log.
To get the latest stable version
gem install backup
You can view the list of released versions over at RubyGems.org (Backup)
I recommend you read this README first, and refer to the Wiki pages afterwards. There's also a Getting Started wiki page.
Below you find a list of components that Backup currently supports. If you'd like support for components other than the ones listed here, feel free to request them or to fork Backup and add them yourself. Backup is modular and easy to extend with new components.
- MySQL
- PostgreSQL
- MongoDB
- Redis
- Files
- Directories
- Amazon Simple Storage Service (S3)
- Rackspace Cloud Files (Mosso)
- Ninefold Cloud Storage
- Dropbox Web Service
- Remote Servers (Available Protocols: FTP, SFTP, SCP and RSync)
- Backup Cycling, applies to:
- Amazon Simple Storage Service (S3)
- Rackspace Cloud Files (Mosso)
- Ninefold Cloud Storage
- Dropbox Web Service
- Remote Servers (Only Protocols: FTP, SFTP, SCP)
- Incremental Backups, applies to:
- Remote Servers (Only Protocols: RSync)
- RSync
- Amazon Simple Storage Service (S3)
- Gzip
- Bzip2
- Lzma
- OpenSSL
- GPG
- Campfire
- Presently
- Ruby 1.9.3-preview1
- Ruby 1.9.2
- Ruby 1.8.7
- Ruby Enterprise Edition 1.8.7
This is a Backup configuration file. Check it out and read the explanation below. Backup has a great wiki which explains each component of Backup in detail.
Backup::Model.new(:sample_backup, 'A sample backup configuration') do
database MySQL do |database|
database.name = 'my_sample_mysql_db'
database.username = 'my_username'
database.password = 'my_password'
database.skip_tables = ['logs']
database.additional_options = ['--single-transaction', '--quick']
end
database MongoDB do |database|
database.name = 'my_sample_mongo_db'
database.only_collections = ['users', 'events', 'posts']
end
archive :user_avatars do |archive|
archive.add '/var/apps/my_sample_app/public/avatars'
end
archive :logs do |archive|
archive.add '/var/apps/my_sample_app/logs/production.log'
archive.add '/var/apps/my_sample_app/logs/newrelic_agent.log'
archive.add '/var/apps/my_sample_app/logs/other/'
archive.exclude '/var/apps/my_sample_app/logs/other/exclude-this.log'
end
encrypt_with OpenSSL do |encryption|
encryption.password = 'my_secret_password'
end
compress_with Gzip do |compression|
compression.best = true
end
store_with S3 do |s3|
s3.access_key_id = 'my_access_key_id'
s3.secret_access_key = 'my_secret_access_key'
s3.region = 'us-east-1'
s3.bucket = 'my_bucket/backups'
s3.keep = 20
end
sync_with S3 do |s3|
s3.access_key_id = "my_access_key_id"
s3.secret_access_key = "my_secret_access_key"
s3.bucket = "my-bucket"
s3.path = "/backups"
s3.mirror = true
s3.directories do |directory|
directory.add "/var/apps/my_app/public/videos"
directory.add "/var/apps/my_app/public/music"
end
end
notify_by Mail do |mail|
mail.on_success = false
mail.on_failure = true
end
notify_by Twitter do |tweet|
tweet.on_success = true
tweet.on_failure = true
end
end
It will dump two databases (MySQL and MongoDB), it'll create two (.t)archives (user_avatars and logs). It'll package the two database and two archives together in a single (.t)archive. It'll run the Gzip compressor to compress that archive, and then it'll run the OpenSSL encryptor to encrypt the compressed archive. Then that encrypted archive will be stored to your Amazon S3 account. If all goes well, and no exceptions are raised, you'll be notified via the Twitter notifier that the backup succeeded. If there was an exception raised during the backup process, then you'd receive an email in your inbox containing detailed exception information, as well as receive a simple Twitter message that something went wrong.
As you can see, you can freely mix and match archives, databases, compressors, encryptors, storages and notifiers for your backups. You could even specify 4 storage locations if you wanted: Amazon S3, Rackspace Cloud Files, Ninefold and Dropbox, it'd then store your packaged backup to 4 separate locations for high redundancy. This also applies to compressors (like Gzip, Bzip2, Lzma) and encryptors, you could double encrypt your backup with OpenSSL followed by GPG if you wanted.
Additionally we have also defined a S3 Syncer ( sync_with S3
), which does not follow the above process of archiving/compression/encryption, but instead will directly sync the whole videos
and music
folder structures from your machine to your Amazon S3 account. (very efficient and cost-effective since it will only transfer files that were added/changed. Additionally, since we flagged it to 'mirror', it'll also remove files from S3 that no longer exist). If you simply wanted to sync to a separate backup server that you own, you could also use the RSync syncer for even more efficient backups that only transfer the bytes of each file that changed.
There are more archives, databases, compressors, encryptors, storages and notifiers than displayed in the example, all available components are listed at the top of this README, as well as in the Wiki with more detailed information.
Notice the Backup::Model.new(:sample_backup, 'A sample backup configuration') do
at the top of the above example. The :sample_backup
is called the trigger. This is used to identify the backup procedure/file and initialize it.
backup perform -t [--trigger] sample_backup
Now it'll run the backup, it's as simple as that.
Since Backup is a simple command line utility, you should write a crontask to invoke it periodically. I recommend you use Whenever to manage your crontab. It'll allow you to write to the crontab in pure Ruby, it provides an elegant DSL to do so, for example:
every 6.hours do
command "backup perform --trigger sample_backup"
end
With this in place, run whenever --update-crontab backup
to write this Ruby syntax to the crontab in cron-syntax. The operating system will now invoke backup perform --trigger sample_backup
every 6 hours. Check out the Whenever project page for more information.
See the Wiki Pages. The subjects labeled without the "Backup 2)"-prefix are meant for Backup 3 users.
View the issue log and post them there.
Contributor | Contribution |
---|---|
Aditya Sanghi ( asanghi ) | Twitter Notifier, Dropbox Timeout Configuration |
Phil Cohen ( phlipper ) | Exclude Option for Archives |
Arun Agrawal ( arunagw ) | Campfire notifier |
Stefan Zimmermann ( szimmermann ) | Enabling package/archive (tar utility) support for more Linux distro's (FreeBSD, etc) |
Mark Nyon ( trystant ) | Helping discuss MongoDump Lock/FSync problem |
Bernard Potocki ( imanel ) | Helping discuss MongoDump Lock/FSync problem + Submitting a patch |
Tomasz Stachewicz ( tomash ) | Helping discuss MongoDump Lock/FSync problem + Submitting a patch |
Paul Strong ( lapluviosilla ) | Helping discuss MongoDump Lock/FSync problem |
Ryan ( rgnitz ) | Helping discuss MongoDump Lock/FSync problem |
Robert Speicher ( tsigo ) | Adding the --quiet [-q] feature to Backup to silence console logging |
Jon Whitcraft ( jwhitcraft ) | Adding the ability to add additional options to the S3Syncer |
Benoit Garret ( bgarret ) | Presently notifier |
Lleïr Borràs Metje ( lleirborras ) | Lzma Compressor |
Jonathan Lassoff ( jof ) | Bugfixes and more secure GPG storage |
Michal Cichra ( mikz ) | Wildcard Triggers |
Dmitry Novotochinov ( trybeee ) | Dropbox Storage |
Emerson Lackey ( Emerson ) | Local RSync Storage |
digilord | OpenSSL Verify Mode for Mail Notifier |
stemps | FTP Passive Mode |
David Kowis ( dkowis ) | Fixed PostgreSQL Password issues |
Jonathan Otto ( jotto ) | Allow for running PostgreSQL as another UNIX user |
João Vitor ( joaovitor ) | Changed default PostgreSQL example options to appropriate ones |
- Fork/Clone the develop branch
- Write RSpec tests, and test against:
- Ruby 1.9.3-preview1
- Ruby 1.9.2
- Ruby 1.8.7
- Ruby Enterprise Edition 1.8.7
- Try to keep the overall structure / design of the gem the same
I can't guarantee I'll pull every pull request. Also, I may accept your pull request and drastically change parts to improve readability/maintainability. Feel free to discuss about improvements, new functionality/features in the issue log before contributing if you need/want more information.
Install RVM and use it to install Ruby 1.9.3, 1.9.2, 1.8.7 and REE.
rvm get latest && rvm reload
rvm install 1.9.3 && rvm install 1.9.2 && rvm install 1.8.7 && rvm install ree
Once these are installed, go ahead and install all the necessary dependencies.
cd backup
rvm use 1.9.3 && gem install bundler && bundle install
rvm use 1.9.2 && gem install bundler && bundle install
rvm use 1.8.7 && gem install bundler && bundle install
rvm use ree && gem install bundler && bundle install
The Backup gem uses Guard along with Guard::RSpec to quickly and easily test Backup's code against all four Rubies. If you've done the above, all you have to do is run:
bundle exec guard
from Backup's root and that's it. It'll now test against all four Rubies each time you adjust a file in the lib
or spec
directories.
- http://erik.debill.org/2011/03/26/csing-backup-with-rails
- http://blog.noizeramp.com/2011/03/31/backing-up-backup-ruby-gem/
- http://www.sebaugereau.com/using-ruby-to-backup-with-beauty
- http://outofti.me/post/4159686269/backup-with-pgbackups
- http://h2ik.co/2011/03/backing-up-with-ruby/
I won't actively support Backup 2 anymore. The source will remain on a separate branch. The Issues that belong to Backup 2 have been tagged with a black label "Backup 2". The Backup 2 specific Wiki pages have been prefixed with "Backup 2)
". The Backup 2 Gems will always remain so you can still use Backup 2. I might still accept pull requests, but would highly encourage anyone to move to Backup 3 once it's here.