Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

ArtStation/chef-backup

 
 

Repository files navigation

Backup Cookbook

![Gitter](https://badges.gitter.im/Join Chat.svg)

This cookbook automates deploying the backup gem and the configuration of any models you may want. With a little work you can backup everything using this cookbook as the framework.

Requirements

packages

  • ruby - ruby is required for the backup gem to be installed. This can be provided either via chef or via other means.
  • libxml2-dev
  • libxslt1-dev

Resources and Providers

This cookbook provides three resources and corresponding providers.

install.rb

Install or Remove the backup gem with this resource.

Actions:

  • install - installs the backup gem
  • remove - removes the backup gem

generate_config.rb

Generate a configuration file for the backup gem with this resource.

Actions:

  • setup - sets up a basic config.rb for the backup gem
  • remove - removes the base directory for the backup gem and everything underneath it.

backup::install

Attribute Type Description Default
version String Version of the backup gem to install

backup::generate_config

Attribute Type Description Default
base_dir String Path where backup and it's configuration files and models reside /opt/backup
cookbook String Cookbook that has the erb template specified in the source to generate config.rb backup
source String Filename of the erb template that generates config.rb config.rb.erb
tmp_path String Directory to store temporary files during backup /tmp
data_path String Directory to store Storage Cycler YAML files /opt/backup/.data

backup::generate_model

Attribute Type Description Default
options Hash Specifies the options used in the backup model
base_dir String Path where backup and it's configuration files and models reside /opt/backup
gem_bin_dir String Path where gem binaries, such as backup, reside (e.g. "/usr/local/bin" ) nil
split_into_chunks_of Fixnum Split the backup archive into multiple smaller files nil
description String Description of the backup
backup_type String What kind of backup? archive or database database
database_type String Type of Database to backup
encrypt_with Hash Hash to specify how to Encrypt backups
compress_with String Specify the Compress Methodd (or disable it) Gzip
store_with Hash Specify what storage engines you wish enable.
sync_with Hash Enable and configure Syncers for this model.
hour String What hour to run the backup 1
minute String How many minutes past the hour to run the backup 0
day String Day of the week to run the backup *
month String Day of the month to run backup *
weekday String Day of the Week to run backup *
mailto String sets the MAILTO variable in the crontab to specify who should get the output of the crontab run
tmp_path String sets the tmp path for the backup
cron_path String sets the PATH variable in the crontab to specify who should get the output of the crontab run /usr/bin:/bin:/usr/local/bin:/opt/chef/embedded/bin
cron_log String Log file for redirecting the cron job output
before_hook String Before hook runs ruby code just after 'Backup' logs that the backup has started, before any procedures are performed
after_hook String After hook runs ruby code just before any Notifiers and is guaranteed to run whether or not the backup process was successful or not
notify_by Hash Hash object that configures Notifiers

Usage

This cookbook is intended to be a framework to help backup your systems. Some examples below:

MongoDB

backup_install node.name
backup_generate_config node.name
gem_package "fog" do
  version "~> 1.4.0"
end
backup_generate_model "mongodb" do
  description "Our shard"
  backup_type "database"
  database_type "MongoDB"
  split_into_chunks_of 2048
  store_with({"engine" => "S3", "settings" => { "s3.access_key_id" => "example", "s3.secret_access_key" => "sample", "s3.region" => "us-east-1", "s3.bucket" => "sample", "s3.path" => "/", "s3.keep" => 10 } } )
  options({"db.host" => "\"localhost\"", "db.lock" => true})
  mailto "some@example.com"
  cron_path "/bin:/usr/bin:/usr/local/bin"
  tmp_path "/mnt/backups"
  cron_log "/var/log/backups.log"
  action :backup
end

PostgreSQL

backup_install node.name
backup_generate_config node.name
gem_package "fog" do
  version "~> 1.4.0"
end
backup_generate_model "pg" do
  description "backup of postgres"
  backup_type "database"
  database_type "PostgreSQL"
  split_into_chunks_of 2048
  store_with({"engine" => "S3", "settings" => { "s3.access_key_id" => "sample", "s3.secret_access_key" => "sample", "s3.region" => "us-east-1", "s3.bucket" => "sample", "s3.path" => "/", "s3.keep" => 10 } } )
  options({"db.name" => "\"postgres\"", "db.username" => "\"postgres\"", "db.password" => "\"somepassword\"", "db.host" => "\"localhost\"" })
  mailto "sample@example.com"
  action :backup
end

Archiving files to S3

backup_install node.name
backup_generate_config node.name
gem_package "fog" do
  version "~> 1.4.0"
end
backup_generate_model "home" do
  description "backup of /home"
  backup_type "archive"
  split_into_chunks_of 250
  store_with({"engine" => "S3", "settings" => { "s3.access_key_id" => "sample", "s3.secret_access_key" => "sample", "s3.region" => "us-east-1", "s3.bucket" => "sample", "s3.path" => "/", "s3.keep" => 10 } } )
  options({"add" => ["/home/","/root/"], "exclude" => ["/home/tmp"], "tar_options" => "-p"})
  mailto "sample@example.com"
  action :backup
end

Notifications

backup_generate_model "archive_attribute_test" do
  description "backup of /etc using additional attributes"
  backup_type "archive"
  split_into_chunks_of 250
  store_with({"engine" => "Local", "settings" => { "local.keep" => 5, "local.path" => "/tmp" } })
  options({"add" => ["/home/","/etc/"], "exclude" => ["/etc/init"], "tar_options" => "-p"})
  mailto "sample@example.com"
  action :backup
  notify_by({"method" => "Campfire", "settings" => {"campfire.on_success" => "true", "campfire.on_warning" => "true", "campfire.on_failure" => "true", "campfire.api_token" => "token", "campfire.subdomain" => "domain", "campfire.room_id" => '34' }})
  gem_bin_dir "/usr/local/bin"
  cron_path "/bin:/usr/bin:/usr/local/bin:/opt/chef/embedded/bin"
  cron_log "/var/log/backups.log"
  tmp_path "/opt/tmp/backups"
end

Syncers

backup_generate_model "sync_my_docs" do
  description  "Backup with RSync::Pull"
  action :backup
  backup_type "syncer"
  gem_bin_dir "/opt/chef/embedded/bin"
  options "add" => ["/home/username/documents", "/home/username/works"],
          "exclude" => ["tmp"]
  sync_with "syncer" => "RSync::Pull",
            "settings" => { "syncer.path" => "/opt/backup/syncs",
                            "syncer.mode" => :ssh,
                            "syncer.additional_ssh_options" => "-i /home/username/.ssh/id_rsa",
                            "syncer.host" => "192.168.0.42",
                            "syncer.ssh_user" => "username" }
end

It is possible to load the settings in an role or an data bag or leave the settings in a recipe.

License and Author

Author:: Scott Likens (scott@likens.us)

Copyright 2014, Scott M. Likens

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Backup Cookbook -- A Chef cookbook to drive backups

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 78.4%
  • HTML 21.6%