]> gitweb.fluxo.info Git - puppet-backupninja.git/commitdiff
install anarcats backupninja module changes
authorMicah Anderson <micah@riseup.net>
Fri, 29 Feb 2008 17:38:32 +0000 (17:38 +0000)
committerMicah Anderson <micah@riseup.net>
Fri, 29 Feb 2008 17:38:32 +0000 (17:38 +0000)
13 files changed:
README
manifests/backupninja.pp [deleted file]
manifests/client.pp [new file with mode: 0644]
manifests/init.pp
manifests/labelmount.pp [new file with mode: 0644]
manifests/mysql.pp
manifests/null_class.pp [deleted file]
manifests/rdiff.pp
manifests/server.pp [new file with mode: 0644]
templates/labelmount.conf.erb [new file with mode: 0644]
templates/labelmount.handler [new file with mode: 0644]
templates/umount.conf.erb [new file with mode: 0644]
templates/umount.handler [new file with mode: 0644]

diff --git a/README b/README
index dffa0ca4eba0f6e355d74771dd963b78eb85f973..b3c3d3a4c697a189f233ee821ba54a1fb9adb73a 100644 (file)
--- 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 (file)
index afd68a4..0000000
+++ /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 (file)
index 0000000..ceb3efb
--- /dev/null
@@ -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
+        }
+}
index 0da5d18429c73cd9058d34e7df4e3b1b7af476ea..8ed54e32d80e3efd824f47971f1eecebcf1a80b1 100644 (file)
@@ -1 +1,5 @@
 import "*.pp"
+
+class backupninja {
+
+}
diff --git a/manifests/labelmount.pp b/manifests/labelmount.pp
new file mode 100644 (file)
index 0000000..ba810f9
--- /dev/null
@@ -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]
+       }
+}
index 0fae221f10814708e9f2795c01503c9ab6d7052f..e2e7442d190e40e11a945449c65728fd167fe777 100644 (file)
@@ -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 (file)
index 9279d87..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-class null_class {
-}
index 9183ef12b0f36d6f24c9ebdf655e495782aef0d5..6e81ab2d171ab40b9197603e99f93de0ca4ddce1 100644 (file)
@@ -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.
 #
 #      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 (file)
index 0000000..40b2dca
--- /dev/null
@@ -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 (file)
index 0000000..e40c49d
--- /dev/null
@@ -0,0 +1,2 @@
+label = <%= label %>
+dest = <%= dest %>
diff --git a/templates/labelmount.handler b/templates/labelmount.handler
new file mode 100644 (file)
index 0000000..22090bd
--- /dev/null
@@ -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 (file)
index 0000000..59bfaec
--- /dev/null
@@ -0,0 +1 @@
+dir = <%= dest %>
diff --git a/templates/umount.handler b/templates/umount.handler
new file mode 100644 (file)
index 0000000..4fea195
--- /dev/null
@@ -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