This cookbook aims to provide a foundation for you to backup your infrastructure. This cookbook helps you deploy the backup gem and generate the models to back up.
Ruby installed either in the system or via omnibus
This cookbook provides three resources and corresponding providers.
Install or Remove the backup gem with this resource.
Actions:
install
- installs the backup gemremove
- removes the backup gem
Attribute Parameters:
version
- specify the version of the backup gem to install
Generate a configuration file for the backup gem with this resource.
Actions:
setup
- sets up a basic config.rb for the backup gemremove
- removes the base directory for the backup gem and everything underneath it.
Attribute Parameters:
base_dir
- String - default to/opt/backup
encryption_password
- String - Provide a passphrase for Encryption - default ofnil
Generates a model file for the backup gem and creates a crontab entry.
Actions:
backup
- Generate a model filedisable
- Disable the scheduled cron for the modelremove
- Remove the model from the system and the scheduled cron.
Attribute Parameters:
base_dir
- String - default to/opt/backup
split_into_chunks_of
- Fixnum - defaults to 250description
- String - Description of backupbackup_type
- String - Type of backup to perform. Current options supported are{database|archive}
store_with
- Hash - Specifies how to store the backupsdatabase_type
- String - If backing up a database, what Type of database is being backed up.hour
- String - Hour to run the scheduled backup - default -1
minute
- String - Minute to run the scheduled backup - default -*
day
- String - Day to run the scheduled backup - default -*
weekday
- String - Weekday to run the scheduled backup - default -*
mailto
- String - Enables the cron resource to mail the output of the backup output.
There are infinite ways you can implement this cookbook into your environment in theory. A working example might be:
- Backing up MongoDB to S3
- Ensure your mongodb cookbook depends on the backup cookbook
- Add the following to your mongodb cookbook
backup_install node.name
backup_generate_config node.name
package "libxml2-dev"
package "libxslt1-dev"
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 "[email protected]"
action :backup
end
- Backing up PostgreSQL to S3
- Ensure your postgresql cookbook depends on the backup cookbook
- Add the following to your postgresql cookbook
backup_install node.name
backup_generate_config node.name
package "libxml2-dev"
package "libxslt1-dev"
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 "[email protected]"
action :backup
end
- Backing up Files to S3
- Ensure the cookbook are updating depends on the backup cookbook.
- Add the following to that cookbook
backup_install node.name
backup_generate_config node.name
package "libxml2-dev"
package "libxslt1-dev"
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 "[email protected]"
action :backup
end
- There is no technical reason you cannot load more of this code in via an
role
or andata bag
instead.
Author:: Scott Likens ([email protected])
Copyright 2012, Scott M. Likens, Inc.
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.
Thank You Heavy Water for contributing the original backup cookbook.