-
Notifications
You must be signed in to change notification settings - Fork 0
Generator
The Backup generator is a very useful little tool to help you set up backups faster.
To bring up the help
screen, run the following command:
$ backup help generate:model
It'll display something like this:
Usage:
backup generate:model --trigger=TRIGGER
Options:
--trigger=TRIGGER
[--config-path=CONFIG_PATH] # Path to your Backup configuration directory
[--databases=DATABASES] # (mongodb, mysql, postgresql, redis, riak)
[--storages=STORAGES] # (cloud_files, dropbox, ftp, local, ninefold, rsync, s3, scp, sftp)
[--syncers=SYNCERS] # (cloud_files, rsync_local, rsync_pull, rsync_push, s3)
[--encryptors=ENCRYPTORS] # (gpg, openssl)
[--compressors=COMPRESSORS] # (bzip2, gzip, lzma, pbzip2)
[--notifiers=NOTIFIERS] # (campfire, hipchat, mail, presently, prowl, twitter)
[--archives]
[--splitter] # use `--no-splitter` to disable
# Default: true
Generates a Backup model file
The options is what makes setting up a Backup configuration file a breeze.
Say you have two databases, a MongoDB and a PostgreSQL database. You want to backup these two databases. You also want to package them up, encrypt them with GPG, compress them with Gzip, store the backup to Amazon S3 and be notified by email if there are any problems.
Additionally you have around 50GB of "user-uploaded-content" in /var/apps/my_app/public/uploads
you would like to keep
a mirror of on Amazon S3 as well.
To get up and running quickly, issue the following command:
$ backup generate:model --trigger my_backup \
--databases="mongodb, postgresql" --storages="s3" --syncers="s3" \
--encryptors="gpg" --compressors="gzip" --notifiers="mail"
This will create a new file: ~/Backup/models/my_backup.rb
(the default location), and the file will look like this:
##
# Backup Generated: my_backup
# Once configured, you can run the backup with the following command:
#
# $ backup perform -t my_backup [-c <path_to_configuration_file>]
#
Backup::Model.new(:my_backup, 'Description for my_backup') do
##
# Split [Splitter]
#
# Split the backup file in to chunks of 250 megabytes
# if the backup file size exceeds 250 megabytes
#
split_into_chunks_of 250
##
# MongoDB [Database]
#
database MongoDB do |db|
db.name = "my_database_name"
db.username = "my_username"
db.password = "my_password"
db.host = "localhost"
db.port = 5432
db.ipv6 = false
db.only_collections = ['only', 'these' 'collections']
db.additional_options = []
db.lock = false
end
##
# PostgreSQL [Database]
#
database PostgreSQL do |db|
db.name = "my_database_name"
db.username = "my_username"
db.password = "my_password"
db.host = "localhost"
db.port = 5432
db.socket = "/tmp/pg.sock"
db.skip_tables = ['skip', 'these', 'tables']
db.only_tables = ['only', 'these' 'tables']
db.additional_options = ['-xc', '-E=utf8']
end
##
# Amazon Simple Storage Service [Storage]
#
# Available Regions:
#
# - ap-northeast-1
# - ap-southeast-1
# - eu-west-1
# - us-east-1
# - us-west-1
#
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 = 'bucket-name'
s3.path = '/path/to/my/backups'
s3.keep = 10
end
##
# Amazon Simple Storage Service [Syncer]
#
sync_with Cloud::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 "/path/to/directory/to/sync"
directory.add "/path/to/other/directory/to/sync"
end
end
##
# GPG [Encryptor]
#
encrypt_with GPG do |encryption|
encryption.key = <<-KEY
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.11 (Darwin)
<Your GPG Public Key Here>
-----END PGP PUBLIC KEY BLOCK-----
KEY
end
##
# Gzip [Compressor]
#
compress_with Gzip do |compression|
compression.best = true
compression.fast = false
end
##
# Mail [Notifier]
#
# The default delivery method for Mail Notifiers is 'SMTP'.
# See the Wiki for other delivery options.
# https://github.com/meskyanichi/backup/wiki/Notifiers
#
notify_by Mail do |mail|
mail.on_success = true
mail.on_warning = true
mail.on_failure = true
mail.from = '[email protected]'
mail.to = '[email protected]'
mail.address = 'smtp.gmail.com'
mail.port = 587
mail.domain = 'your.host.name'
mail.user_name = '[email protected]'
mail.password = 'my_password'
mail.authentication = 'plain'
mail.enable_starttls_auto = true
end
end
Just omit what you don't need, and change what you do need and you're done.
Note: If you want to change the path where the model file will be generated, use the --config-path
option.
--config-path
is the path where Backup's main configuration file is located.
So, if you have your main configuration file in /path/to/config.rb
, then you would generate your models using:
$ backup generate:model --config-path='/path/to/' --trigger (etc...)
Generating the model above will also create the main Backup configuration file: ~/Backup/config.rb
##
# Backup
# Generated Main Config Template
#
# For more information:
#
# View the Git repository at https://github.com/meskyanichi/backup
# View the Wiki/Documentation at https://github.com/meskyanichi/backup/wiki
# View the issue log at https://github.com/meskyanichi/backup/issues
##
# Global Configuration
# Add more (or remove) global configuration below
Backup::Storage::S3.defaults do |s3|
# s3.access_key_id = "my_access_key_id"
# s3.secret_access_key = "my_secret_access_key"
end
Backup::Encryptor::OpenSSL.defaults do |encryption|
# encryption.password = "my_password"
# encryption.base64 = true
# encryption.salt = true
end
##
# Load all models from the models directory (after the above global configuration blocks)
Dir[File.join(File.dirname(Config.config_file), "models", "*.rb")].each do |model|
instance_eval(File.read(model))
end
The main configuration file is setup to automatically include all of your generated models. This is where you will specify your global defaults.
If you need to re-generate only this main configuration file, you can do so using:
$ backup generate:config
By default, Backup will look for this file in ~/Backup/config.rb
.
If you want to place your configuration files in a different location, use the --config_file
option:
$ backup perform --trigger my_backup --config_file '/path/to/config.rb'
If you relocate this file, be sure to move the models
directory as well. Or, if you're only going to configure one
backup job (or a few simple ones), you can remove the last few lines from config.rb
and replace this with the contents
of your models/my_backup.rb
file(s). You can have as many models
configured within config.rb
as you like.