Backup - abletech/easy-deployment GitHub Wiki
This feature aims to takeaway the hassle of easily setting up backup of your data to S3.
It uses the backup
and whenever
gems to setup a cron task that dumps your database, and compresses it and along with any configured file directories such as uploads that you may have, uploads the data to S3.
Requirements
- Easy Deployment 0.5.0 and up (latest always recommended)
- An Amazon S3 account
- Rails 3.2+
Installation
From 0.5.0 and up Easy Deployment will set this up by default as part of the installation process. To re-run the generator for the backup configuration:
rails generate easy:backup
bundle install
This will insert a section into your Gemfile for the gems that are used by the backup process. These are set to require => false
because they are not needed during normal execution of your application.
E.g.
# Gemfile
group :backup do
gem "whenever", :require => false
gem "backup", "~> 3.1.3", :require => false
gem "fog", "~> 1.9.0", :require => false
gem "net-ssh", ['>= 2.3.0', '<= 2.5.2'], :require => false
gem "net-scp", ['>= 1.0.0', '<= 1.0.4'], :require => false
gem "excon", "~> 0.17.0", :require => false
gem "mail", "~> 2.5.0", :require => false
end
NOTE: Depending on your rails version, you may get an error running bundle install at this point due to some secondary dependencies of libraries between capistrano and the specific versions used by the backup gem. The likely causes are the net-*
gems. Try running bundle update net-ssh net-scp net-ssh-gateway net-sftp net-scp
so that bundler knows it's okay to change the versions of those gems, or resorting to bundle update
to update all gems to the latest allowable by the constraints in the Gemfile.
Ensure your deploy.rb
has the following: (compare against the latest template if you are not sure)
# deploy.rb
# Backup
require "easy/deployment/backup"
require "whenever/capistrano"
set :whenever_command, "#{fetch(:bundle_cmd, "bundle")} exec whenever"
You will also need to update the various configuration files as described below:
Configuration
s3.yml
There will be a file generated to config/s3.yml
. Put your S3 credentials in here, and fill in the bucket and region values as well. It is strongly recommended that the credentials you use here have been created specifically for the purpose of backup, and only have access to upload to the bucket/path that is specified here. (because you don't want a compromise of those credentials to be able to delete or alter your backups).
backup.rb
The Easy Deployment generator will create a config/backup.rb
file, which Contains the details for which files and databases to backup and how to backup them up. By default, the generator should correctly produce a configuration which already setup to dump a Postgresql or Mongodb database, and to backup the files in the capistrano system folder (DEPLOY_TO/shared/system
), which is commonly where file uploads are stored.
Read more about how to configure this file in the backup gem documentation
schedule.rb
This details when to run the backup config/schedule.rb
and uses the whenever
gem to write the crontab for your deploy user to accomplish this.
You should:
- Ensure that
base_path
andapplication
have the same values as they do indeploy.rb
- Adjust the time that the backup runs as necessary for your traffic profile and server timezone.
Read more about options for configuring this file in the whenever gem documentation