aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README13
-rw-r--r--manifests/backupninja.pp5
-rw-r--r--manifests/client.pp12
-rw-r--r--manifests/init.pp4
-rw-r--r--manifests/labelmount.pp63
-rw-r--r--manifests/mysql.pp21
-rw-r--r--manifests/null_class.pp2
-rw-r--r--manifests/rdiff.pp27
-rw-r--r--manifests/server.pp53
-rw-r--r--templates/labelmount.conf.erb2
-rw-r--r--templates/labelmount.handler17
-rw-r--r--templates/umount.conf.erb1
-rw-r--r--templates/umount.handler15
13 files changed, 194 insertions, 41 deletions
diff --git a/README b/README
index dffa0ca..b3c3d3a 100644
--- a/README
+++ b/README
@@ -26,6 +26,19 @@ backupninja::rdiff { backup_all:
exclude => '/home/*/.gnupg'
}
+A remove rdiff backup handler:
+
+ backupninja::rdiff { "main":
+ host => "backup.example.com",
+ type => "remote",
+ directory => "/backup/$fqdn",
+ user => "backup-$hostname",
+ }
+
+If you configure a backupninja::server, it will collect those users and create
+them. We have yet to create proper authorized_keys management to make that
+process completely automatic.
+
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
diff --git a/manifests/backupninja.pp b/manifests/backupninja.pp
deleted file mode 100644
index afd68a4..0000000
--- a/manifests/backupninja.pp
+++ /dev/null
@@ -1,5 +0,0 @@
-class backupninja {
- package { 'backupninja':
- ensure => '0.9.5-3'
- }
-}
diff --git a/manifests/client.pp b/manifests/client.pp
new file mode 100644
index 0000000..ceb3efb
--- /dev/null
+++ b/manifests/client.pp
@@ -0,0 +1,12 @@
+class backupninja::client {
+ $configdir = $cfg_override ? {
+ '' => "/etc/backup.d",
+ default => $cfg_override,
+ }
+ package { 'backupninja':
+ ensure => '0.9.5-3';
+ }
+ file { $configdir:
+ ensure => directory
+ }
+}
diff --git a/manifests/init.pp b/manifests/init.pp
index 0da5d18..8ed54e3 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -1 +1,5 @@
import "*.pp"
+
+class backupninja {
+
+}
diff --git a/manifests/labelmount.pp b/manifests/labelmount.pp
new file mode 100644
index 0000000..ba810f9
--- /dev/null
+++ b/manifests/labelmount.pp
@@ -0,0 +1,63 @@
+# Mount a labelled partition on a directory as part of a backupninja run.
+#
+# This type will automatically create an unmount action with an order of 99
+# for the destination directory you specify here.
+#
+# Valid attributes for this type are:
+#
+# order: The prefix to give to the handler config filename, to set
+# order in which the actions are executed during the backup run. Note
+# that the value given here should be less than any action which
+# requires the filesystem to be mounted!
+#
+# 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).
+#
+# label: The partition label to mount.
+#
+# dest: The directory to mount the partition onto.
+#
+define backupninja::labelmount($order = 10,
+ $ensure = present,
+ $label,
+ $dest
+ ) {
+ include backupninja::client
+ file { "${backup::client::configdir}/${order}_${name}.labelmount":
+ ensure => $ensure,
+ content => template('backupninja/labelmount.conf.erb'),
+ owner => root,
+ group => root,
+ mode => 0600,
+ require => File["${backup::client::configdir}"]
+ }
+
+ file { "${backup::client::configdir}/99_${name}.umount":
+ ensure => $ensure,
+ content => template('backupninja/umount.conf.erb'),
+ owner => root,
+ group => root,
+ mode => 0600,
+ require => File["${backup::client::configdir}"]
+ }
+
+ # Copy over the handler scripts themselves, since they're not in the
+ # standard distribution, and are unlikely to end up there any time
+ # soon because backupninja's "build" system is balls.
+ file { "/usr/share/backupninja/labelmount":
+ content => template('backupninja/labelmount.handler'),
+ owner => root,
+ group => root,
+ mode => 0755,
+ require => Package[backupninja]
+ }
+
+ file { "/usr/share/backupninja/umount":
+ content => template('backupninja/umount.handler'),
+ owner => root,
+ group => root,
+ mode => 0755,
+ require => Package[backupninja]
+ }
+}
diff --git a/manifests/mysql.pp b/manifests/mysql.pp
index 0fae221..e2e7442 100644
--- a/manifests/mysql.pp
+++ b/manifests/mysql.pp
@@ -2,8 +2,6 @@
#
# 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.
#
@@ -16,8 +14,7 @@
# 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,
+define backupninja::mysql($order = 10,
$ensure = present,
$user = false,
$dbusername = false,
@@ -30,23 +27,13 @@ define backupninja::mysql($configdir = '/etc/backup.d',
$compress = false,
$configfile = '/etc/mysql/debian.cnf'
) {
- # 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":
+ include backupninja::client
+ file { "${backup::client::configdir}/${order}_${name}.mysql":
ensure => $ensure,
content => template('backupninja/mysql.conf.erb'),
owner => root,
group => root,
mode => 0600,
- require => File["${configdir}"]
+ require => File["${backupninja::client::configdir}"]
}
}
diff --git a/manifests/null_class.pp b/manifests/null_class.pp
deleted file mode 100644
index 9279d87..0000000
--- a/manifests/null_class.pp
+++ /dev/null
@@ -1,2 +0,0 @@
-class null_class {
-}
diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp
index 9183ef1..6e81ab2 100644
--- a/manifests/rdiff.pp
+++ b/manifests/rdiff.pp
@@ -2,8 +2,6 @@
#
# 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.
#
@@ -17,36 +15,31 @@
# options should be given as arrays if you want to specify multiple
# directories.
#
-define backupninja::rdiff($configdir = '/etc/backup.d',
- $order = 90,
+define backupninja::rdiff($order = 90,
$ensure = present,
$user = false,
$directory = false,
$host = false,
$type = 'local',
- $exclude = false,
- $include = false,
+ $exclude = [ "/home/*/.gnupg", "/home/*/.local/share/Trash", "/home/*/.Trash", "/home/*/.thumbnails", "/home/*/.beagle", "/home/*/.aMule", "/home/*/gtk-gnutella-downloads" ],
+ $include = [ "/var/spool/cron/crontabs", "/var/backups", "/etc", "/root", "/home", "/usr/local/*bin", "/var/lib/dpkg/status*" ],
$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
+ include backupninja::client
+ case $type {
+ 'remote': {
+ case $host { false: { err("need to define a host for remote backups!") } }
+ backupninja::server::sandbox { $user: host => $host, dir => $directory }
}
}
-
- file { "${configdir}/${order}_${name}.rdiff":
+ file { "${backupninja::client::configdir}/${order}_${name}.rdiff":
ensure => $ensure,
content => template('backupninja/rdiff.conf.erb'),
owner => root,
group => root,
mode => 0600,
- require => File["${configdir}"]
+ require => File["${backupninja::client::configdir}"]
}
}
diff --git a/manifests/server.pp b/manifests/server.pp
new file mode 100644
index 0000000..40b2dca
--- /dev/null
+++ b/manifests/server.pp
@@ -0,0 +1,53 @@
+class backupninja::server {
+ $backupdir = $backupdir_override ? {
+ '' => "/backup",
+ default => $backupdir_override,
+ }
+ group { "backupninjas":
+ ensure => "present",
+ gid => 700
+ }
+ file { "$backupdir":
+ ensure => "directory",
+ mode => 750, owner => root, group => "backupninjas"
+ }
+ User <<| tag == "backupninja-$fqdn" |>>
+
+ # this define allows nodes to declare a remote backup sandbox, that have to
+ # get created on the server
+ define sandbox($host, $dir = false, $uid = false, $gid = "backupninjas") {
+ $real_dir = $dir ? {
+ false => "${backupninja::server::backupdir}/$fqdn",
+ default => $dir,
+ }
+ case $uid {
+ false: {
+ @@user { "$name":
+ ensure => "present",
+ gid => "$gid",
+ comment => "$name backup sandbox",
+ home => "$real_dir",
+ managehome => true,
+ shell => "/bin/sh",
+ password => '*',
+ require => [ Group['backupninjas'], File["/backup"] ],
+ tag => "backupninja-$host"
+ }
+ }
+ default: {
+ @@user { "$name":
+ ensure => "present",
+ uid => "$uid",
+ gid => "$gid",
+ comment => "$name backup sandbox",
+ home => "$real_dir",
+ managehome => true,
+ shell => "/bin/sh",
+ password => '*',
+ require => [ Group['backupninjas'], File["/backup"] ],
+ tag => "backupninja-$host"
+ }
+ }
+ }
+ }
+}
diff --git a/templates/labelmount.conf.erb b/templates/labelmount.conf.erb
new file mode 100644
index 0000000..e40c49d
--- /dev/null
+++ b/templates/labelmount.conf.erb
@@ -0,0 +1,2 @@
+label = <%= label %>
+dest = <%= dest %>
diff --git a/templates/labelmount.handler b/templates/labelmount.handler
new file mode 100644
index 0000000..22090bd
--- /dev/null
+++ b/templates/labelmount.handler
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# Mount a block device with the specified label ('label') onto the given
+# directory ('dest').
+
+getconf label
+getconf dest
+
+if [ ! -b "/dev/disk/by-label/$label" ]; then
+ halt "No partition labelled '$label' is available"
+fi
+
+if [ ! -d "$dest" ]; then
+ halt "Destination directory does not exist"
+fi
+
+mount -t auto /dev/disk/by-label/$label $dest || halt "Mount failed"
diff --git a/templates/umount.conf.erb b/templates/umount.conf.erb
new file mode 100644
index 0000000..59bfaec
--- /dev/null
+++ b/templates/umount.conf.erb
@@ -0,0 +1 @@
+dir = <%= dest %>
diff --git a/templates/umount.handler b/templates/umount.handler
new file mode 100644
index 0000000..4fea195
--- /dev/null
+++ b/templates/umount.handler
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Unmount the specified directory ('dir'), forcefully if necessary.
+
+getconf dir
+
+if ! umount $dir; then
+ warning "Simple unmount failed for $dir; being forceful"
+ if ! umount -f $dir; then
+ warning "Forceful unmount failed for $dir; being lazy"
+ if ! umount -l $dir; then
+ warning "Lazy unmount failed for $dir; you're on your own"
+ fi
+ fi
+fi