Public | Automated Build

Last pushed: 2 years ago
Short Description
Short description is empty for this repo.
Full Description

docker-backup-base

Base Dockerfile for Using the Backup Gem inside a docker container. This base currently installs mongodb tools, postgres client tools, gnupg, the backup gem and the whenever gem.

Use this as your base image, then ADD your Backup/config.rb, Backup/models/*, and your schedule.rb. Something like this:

FROM danhixon/backup-base
# backup_passphrase contains your gnupg passphrase.
ADD backup_passphrase /root/backup_passphrase
RUN mkdir -p /root/Backup/models
ADD config.rb /root/Backup/config.rb
ADD models/my_backups.rb /root/Backup/models/my_backups.rb

RUN mkdir -p /root/Whenever/config
ADD schedule.rb /root/Whenever/config/schedule.rb
RUN cd /root/Whenever ; whenever --write-crontab

After building the file run the container with your S3 credentials and links to the database servers:

docker run --name backups --link postgres:pg --link mongo:mongodb -e AWS_ACCESS_KEY_ID=#{pg_appuser} -e AWS_SECRET_ACCESS_KEY=#{pg_appuser_password} awesome_app/backup

#Sample Files

###Backup/models/backups.rb
Model.new(:hourly_backup, 'PostgreSQL and MongoDB Hourly (24)') do
database MongoDB
database PostgreSQL
encrypt_with GPG
compress_with Gzip
notify_by Mail

  store_with S3 do |s3|
    s3.keep  = 24
    s3.path  = "/db/hourly/"
  end
end

Model.new(:daily_backup, 'PostgreSQL and MongoDB Daily (7)') do
  database MongoDB
  database PostgreSQL      
  encrypt_with GPG
  compress_with Gzip
  notify_by Mail

  store_with S3 do |s3|
    s3.keep     = 7
    s3.path  = "/db/daily/"
  end
end

###Backup/config.rb

Backup::Database::PostgreSQL.defaults do |db|
  db.database           = "awesome_app"
  db.username           = ENV['PG_ENV_POSTGRESQL_USER']
  db.password           = ENV['PG_ENV_POSTGRESQL_PASSWORD']
  db.host               = ENV['PG_PORT_5432_TCP_ADDR']
  db.port               = ENV['PG_PORT_5432_TCP_PORT']
  # When dumping all databases, `skip_tables` and `only_tables` are ignored.
  #db.skip_tables        = ["skip", "these", "tables"]
  #db.only_tables        = ["only", "these", "tables"]
  db.additional_options = ["-Fc", "-E=utf8","--no-acl","--no-owner"]
end

Backup::Database::MongoDB.defaults do |db|
  db.database           = "awesome_app"
  db.username           = ENV['MONGODB_ENV_USER']
  db.password           = ENV['MONGODB_ENV_USER_PASSWORD']
  db.host               = ENV['MONGODB_PORT_27017_TCP_ADDR']
  db.port               = ENV['MONGODB_PORT_27017_TCP_PORT']
  db.ipv6               = false
  #db.only_collections   = ["only", "these", "collections"]
  db.additional_options = []
  db.lock               = false
  db.oplog              = false
end

Backup::Storage::S3.defaults do |s3|
  s3.access_key_id     = ENV["AWS_ACCESS_KEY_ID"]
  s3.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
  s3.bucket            = "backups.domain.com"
end

Encryptor::GPG.defaults do |gpg|
    # gpg.gpg_homedir = 
    gpg.keys = {}
    gpg.keys['dan.hixon@email.com'] = <<-KEY
      -----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

mQENBFNQQGMBexJfaytN6xgD90Oyo2a2r+DzuO122fuEN+8R4nh
N81LXSfVukfU+xAaK95ASLHoLfXAdubTr23mE+XkVNFJJFSnMtcfYvYIJR7StQii
/q87TNTKwJvX+V5s+OMKWz5V/JZlRY6BJ0bcIR8PzAWRTPbEkluljNhN2p70rF4U
r4CqZNVQrbTPFyZdN06TJk+5982C5QRnfm27fZkCn8V7PZkzzARZP1uIVoYnqIaA
Fx38x6HOPhUNnYnpwQH5eE1+RrKHc/1xfjxyxa7FdTE90jJk3HoIPLlSXI2pZNpt
tpWxYdcHLPP7aaSPjc+mrPTcuJM8gHWpHYpHABEBAAG0PURhbmllbCBIaXhvbiAo
Q2hpZWYgVGVjaG5vbG9naXN0KSA8ZGFuLmhpeG9uQGNoYXR0ZXJwbHVnLmNvbT6J
ATgEEwECACIFAlNQQGMCwwMGCwkIBwmCBhUIAgkKCwQWAgMBAh4BAheAAAoJECZr
H2SjRyNlGbQH/Rx3meb6fwnYy3aHdE7EMkgr9zKZd9pZgHR4X8DFuhPzpjy2+sDP
rIbLToqKqPMiLfFhR73W/y93Aj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:symmetric or :both)
  gpg.mode = :both # defaults to :asymmetric
    # Specify recipients from #keys (for :asymmetric encryption)
  gpg.recipients = ['dan.hixon@email.com']
  # Specify passphrase or passphrase_file (for :symmetric encryption)
  #encryption.passphrase = ENV['ENCRYPTION_PASSPHRASE']
  gpg.passphrase_file = '~/backup_passphrase'
end

Notifier::Mail.defaults do |mail|
  mail.on_success           = true
  mail.on_warning           = true
  mail.on_failure           = true
  mail.from                 = 'sender@email.com'
  mail.to                   = 'receiver@email.com'
  mail.address              = 'smtp.gmail.com'
  mail.port                 = 587
  mail.domain               = 'your.host.name'
  mail.user_name            = 'sender@email.com'
  mail.password             = 'my_password'
  mail.authentication       = 'plain'
  mail.encryption           = :starttls
end

###schedule.rb
Note that I've changed the job template to import the container environment variables.

set :output, "/root/cron.log"
# Get the environment variables from /etc/container_environment.sh
set :job_template, "bash -l -c 'source /etc/container_environment.sh ; :job'"

every 1.day, :at => '5:09 am' do
  command "/usr/local/bin/backup perform -t daily_backup"
end

every :hour do
    command "/usr/local/bin/backup perform -t hourly_backup"
end
Docker Pull Command
Owner
spiddy
Source Repository