Commit 794856bf authored by Micah Anderson's avatar Micah Anderson

add backupninja module

parents
Backupninja Module
-------------------
Configure Backupninja handlers via Puppet.
Simply include backupninja (to make sure you've got the package installed)
then configure backupninja:
backupninja::config { conf:
loglvl => 3,
usecolors => false
}
And setup your handlers:
backupninja::mysql { all_databases:
user => root,
backupdir => '/var/backups',
compress => true,
sqldump => true
}
backupninja::rdiff { backup_all:
directory => '/media/backupdisk',
include => ['/var/backups', '/home', '/var/lib/dpkg/status'],
exclude => '/home/*/.gnupg'
}
At the moment, only the mysql and rdiff handlers have types defined for
them, as they're the only handlers we currently use at Solutions First.
Writing others is fairly simple; feel free to contribute them, or ask really
nicely and we might have a bit a free time.
class backupninja {
package { 'backupninja':
ensure => present
}
}
# Write a "main" configuration file for backupninja. Effectively, it does
# little more than just take the config options you specify in the define and
# write them to the config file as-is.
#
define backupninja::config($configfile = '/etc/backupninja.conf',
$loglvl = 4,
$when = '01:00',
$reportemail = 'root',
$reportsuccess = false,
$reportwarning = true,
$logfile = '/var/log/backupninja.log',
$configdir = '/etc/backup.d',
$scriptdir = '/usr/share/backupninja',
$usecolors = true
) {
file { $configfile:
content => template('backupninja/backupninja.conf.erb'),
owner => root,
group => root,
mode => 0644
}
}
import "*.pp"
# Safe MySQL dumps, as part of a backupninja run.
#
# Valid attributes for this type are:
#
# configdir: The directory to write the handler config file into.
#
# order: The prefix to give to the handler config filename, to set
# order in which the actions are executed during the backup run.
#
# ensure: Allows you to delete an entry if you don't want it any more
# (but be sure to keep the configdir, name, and order the same, so
# that we can find the correct file to remove).
#
# user, dbusername, dbpassword, dbhost, databases, backupdir, hotcopy,
# sqldump, compress: As defined in the backupninja documentation, with the
# caveat that hotcopy, sqldump, and compress take true/false rather
# than yes/no.
#
define backupninja::mysql($configdir = '/etc/backup.d',
$order = 10,
$ensure = present,
$user = false,
$dbusername = false,
$dbpassword = false,
$dbhost = 'localhost',
$databases = 'all',
$backupdir = false,
$hotcopy = false,
$sqldump = false,
$compress = false
) {
# Make sure the directory that the config goes into exists already
if defined(File["${configdir}"]) {
# Yay for a lack of a negation operator, and the inability
# to provide empty blocks
include null_class
} else {
file { $configdir:
ensure => directory
}
}
file { "${configdir}/${order}_${name}.mysql":
ensure => $ensure,
content => template('backupninja/mysql.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${configdir}"]
}
}
class null_class {
}
# Run rdiff-backup as part of a backupninja run.
#
# Valid attributes for this type are:
#
# configdir: The directory to write the handler config file into.
#
# order: The prefix to give to the handler config filename, to set
# order in which the actions are executed during the backup run.
#
# ensure: Allows you to delete an entry if you don't want it any more
# (but be sure to keep the configdir, name, and order the same, so
# that we can find the correct file to remove).
#
# keep, include, exclude, type, host, directory, user, sshoptions: As
# defined in the backupninja documentation. The options will be placed
# in the correct sections automatically. The include and exclude
# options should be given as arrays if you want to specify multiple
# directories.
#
define backupninja::rdiff($configdir = '/etc/backup.d',
$order = 90,
$ensure = present,
$user = false,
$directory = false,
$host = false,
$type = 'local',
$exclude = false,
$include = false,
$keep = 30,
$sshoptions = false,
$options = false
) {
# Make sure the directory that the config goes into exists already
if defined(File["${configdir}"]) {
# Yay for a lack of a negation operator, and the inability
# to provide empty blocks
include null_class
} else {
file { $configdir:
ensure => directory
}
}
file { "${configdir}/${order}_${name}.rdiff":
ensure => $ensure,
content => template('backupninja/rdiff.conf.erb'),
owner => root,
group => root,
mode => 0600,
require => File["${configdir}"]
}
}
# This configuration file was auto-generated by the Puppet configuration
# management system. Any changes you make to this file will be overwritten
# the next time Puppet runs. Please make configuration changes to this
# service in Puppet.
loglevel = <%= loglvl %>
when = <%= send(:when) %>
reportemail = <%= reportemail %>
reportsuccess = <%= reportsuccess ? 'yes' : 'no' %>
reportwarning = <%= reportwarning ? 'yes' : 'no' %>
logfile = <%= logfile %>
configdirectory = <%= configdir %>
scriptdirectory = <%= scriptdir %>
usecolors = <%= usecolors ? 'yes' : 'no' %>
# This configuration file was auto-generated by the Puppet configuration
# management system. Any changes you make to this file will be overwritten
# the next time Puppet runs. Please make configuration changes to this
# service in Puppet.
<% %w{user dbusername dbpassword dbhost databases backupdir}.each do |v|
if send(v)
-%><%= v + ' = ' + send(v) + "\n" %><%
end
end -%>
hotcopy = <%= hotcopy ? 'yes' : 'no' %>
sqldump = <%= sqldump ? 'yes' : 'no' %>
compress = <%= compress ? 'yes' : 'no' %>
# This configuration file was auto-generated by the Puppet configuration
# management system. Any changes you make to this file will be overwritten
# the next time Puppet runs. Please make configuration changes to this
# service in Puppet.
<%= 'options = ' + options if options %>
[source]
type = local
<%= 'keep = ' + keep if keep %>
<% if include.is_a? String -%>
<%= 'include = ' + include %>
<% elsif include.is_a? Array -%>
<%= include.map { |i| "include = #{i}" }.join("\n") %>
<% end -%>
<% if exclude.is_a? String -%>
<%= 'exclude = ' + exclude %>
<% elsif exclude.is_a? Array -%>
<%= exclude.map { |i| "exclude = #{i}" }.join("\n") %>
<% end -%>
[dest]
<% %w{type host directory user sshoptions}.each do |v|
if @scope.lookupvar(v)
-%><%= v + ' = ' + @scope.lookupvar(v) + "\n" %><%
end
end -%>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment