aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2007-11-20 03:14:55 +0000
committerMicah Anderson <micah@riseup.net>2007-11-20 03:14:55 +0000
commit794856bfff4f93066570f06280170609794e157a (patch)
tree47443fdbd76cf220711cfb4c2c1457b865e25598
downloadpuppet-backupninja-794856bfff4f93066570f06280170609794e157a.tar.gz
puppet-backupninja-794856bfff4f93066570f06280170609794e157a.tar.bz2
add backupninja module
-rw-r--r--README32
-rw-r--r--manifests/backupninja.pp5
-rw-r--r--manifests/config.pp22
-rw-r--r--manifests/init.pp1
-rw-r--r--manifests/mysql.pp51
-rw-r--r--manifests/null_class.pp2
-rw-r--r--manifests/rdiff.pp52
-rw-r--r--templates/backupninja.conf.erb14
-rw-r--r--templates/mysql.conf.erb14
-rw-r--r--templates/rdiff.conf.erb29
10 files changed, 222 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..dffa0ca
--- /dev/null
+++ b/README
@@ -0,0 +1,32 @@
+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.
diff --git a/manifests/backupninja.pp b/manifests/backupninja.pp
new file mode 100644
index 0000000..1de0f55
--- /dev/null
+++ b/manifests/backupninja.pp
@@ -0,0 +1,5 @@
+class backupninja {
+ package { 'backupninja':
+ ensure => present
+ }
+}
diff --git a/manifests/config.pp b/manifests/config.pp
new file mode 100644
index 0000000..7cf5b1a
--- /dev/null
+++ b/manifests/config.pp
@@ -0,0 +1,22 @@
+# 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
+ }
+}
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..0da5d18
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1 @@
+import "*.pp"
diff --git a/manifests/mysql.pp b/manifests/mysql.pp
new file mode 100644
index 0000000..92f6729
--- /dev/null
+++ b/manifests/mysql.pp
@@ -0,0 +1,51 @@
+# 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}"]
+ }
+}
diff --git a/manifests/null_class.pp b/manifests/null_class.pp
new file mode 100644
index 0000000..9279d87
--- /dev/null
+++ b/manifests/null_class.pp
@@ -0,0 +1,2 @@
+class null_class {
+}
diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp
new file mode 100644
index 0000000..9183ef1
--- /dev/null
+++ b/manifests/rdiff.pp
@@ -0,0 +1,52 @@
+# 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}"]
+ }
+}
diff --git a/templates/backupninja.conf.erb b/templates/backupninja.conf.erb
new file mode 100644
index 0000000..16579ab
--- /dev/null
+++ b/templates/backupninja.conf.erb
@@ -0,0 +1,14 @@
+# 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' %>
diff --git a/templates/mysql.conf.erb b/templates/mysql.conf.erb
new file mode 100644
index 0000000..a26976a
--- /dev/null
+++ b/templates/mysql.conf.erb
@@ -0,0 +1,14 @@
+# 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' %>
diff --git a/templates/rdiff.conf.erb b/templates/rdiff.conf.erb
new file mode 100644
index 0000000..2906dc4
--- /dev/null
+++ b/templates/rdiff.conf.erb
@@ -0,0 +1,29 @@
+# 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 -%>