Install RVM (Or Rbenv) to manage your Ruby versions
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ curl -sSL https://get.rvm.io | bash
Restart Terminal and type rvm -v
$ rvm install 2.5
$ rvm gemset create backup
$ rvm gemset use backup
$ gem install backup
$ backup generate:model --trigger project_2_backup --archives --storages='s3' --compressor='gzip' --notifiers='mail'
Generated configuration file: '/home/ubuntu/Backup/config.rb'.
Generated model file: '/home/ubuntu/Backup/models/project_2_backup.rb'.
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] # (cloudfiles, 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
Sample Model File
Add the following conf in Backup/models/project_2_backup.rb:
Example for mongodb
database MongoDB do |db|
db.name = "db_name"
db.username = "db_username"
db.password = "db_pswd"
db.host = "localhost"
db.port = 27017
db.ipv6 = false
#db.only_collections = ["only", "these", "collections"]
db.additional_options = ['--authenticationDatabase=admin']
db.lock = false
db.oplog = false
end
##
# Amazon Simple Storage Service [Storage]
#
store_with S3 do |s3|
# AWS Credentials
s3.access_key_id = "YOUR_ACCESS_KEY"
s3.secret_access_key = "YOUR_SECRET_KEY"
# Or, to use a IAM Profile:
# s3.use_iam_profile = true
s3.region = "ap-southeast-2"
s3.bucket = "bucket_name"
s3.path = "bucket_name_path"
s3.keep = 12
# s3.keep = Time.now - 2592000 # Remove all backups older than 1 month.
end
# Notification mail infos
notify_by Mail do |mail|
mail.on_success = true
mail.on_warning = true
mail.on_failure = true
mail.from = "_____@gmail.com"
mail.to = "____@___.com"
mail.cc = "______@_____.com, _____@______.com"
#mail.bcc = "bcc@email.com"
#mail.reply_to = "reply_to@email.com"
mail.address = "smtp.gmail.com"
mail.port = 587
mail.domain = "domain_name"
mail.user_name = "email_username"
mail.password = "email_password"
mail.authentication = "plain"
mail.encryption = :starttls
end
Once you’ve setup your configuration, check your work with:
$ backup check
If there are no errors, the check should report:
[2019/03/28 10:02:26][info] Configuration Check Succeeded.
Perform Backup:
$ backup perform --trigger project_2_backup
The Keep Option
keep
a specified number of backups in storage. After each backup is performed, it will remove older backup package files based on the keep setting.
keep as a Number
If a number has been specified and once the keep limit has been reached, the oldest backup will be removed.
Note that if keep is set to 5, then the 6th backup will be transferred and stored, before the oldest is removed. So be sure you have space available for keep + 1 backups
keep as Time
When a Time object is set to keep it will keep backups until that time. Everything older than the set time will be removed.