From 37a6a9feb1a3674c9d7d8cea162acc253e035d56 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Sat, 6 Dec 2008 19:36:54 -0500 Subject: allow disabling the configfile parameter completely, put it in the config file properly --- manifests/mysql.pp | 8 +++++++- templates/mysql.conf.erb | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/manifests/mysql.pp b/manifests/mysql.pp index e7c0eb4..08af103 100644 --- a/manifests/mysql.pp +++ b/manifests/mysql.pp @@ -17,9 +17,15 @@ define backupninja::mysql( $order = 10, $ensure = present, $user = false, $dbusername = false, $dbpassword = false, $dbhost = 'localhost', $databases = 'all', $backupdir = false, $hotcopy = false, - $sqldump = false, $compress = false, $configfile = '/etc/mysql/debian.cnf', + $sqldump = false, $compress = false, $configfile = true, $vsname = false) { + + $real_config_file = $configfile ? { + true => "/etc/mysql/debian.cnf", + default => $configfile, + } + include backupninja::client file { "${backupninja::client::configdir}/${order}_${name}.mysql": ensure => $ensure, diff --git a/templates/mysql.conf.erb b/templates/mysql.conf.erb index 9d22ab0..14905fd 100644 --- a/templates/mysql.conf.erb +++ b/templates/mysql.conf.erb @@ -12,3 +12,7 @@ end -%> hotcopy = <%= hotcopy ? 'yes' : 'no' %> sqldump = <%= sqldump ? 'yes' : 'no' %> compress = <%= compress ? 'yes' : 'no' %> + +<% if real_configfile %> +configfile = <%= real_configfile %> +<% end %> -- cgit v1.2.3 From ddab7a22876a664c17a4a98ad536b97c36496bd6 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Sat, 6 Dec 2008 19:43:19 -0500 Subject: make the user depend on its home so it gets created properly --- manifests/server.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/server.pp b/manifests/server.pp index 162d889..e4298ef 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -98,7 +98,7 @@ class backupninja::server { managehome => true, shell => "/bin/sh", password => '*', - require => Group['backupninjas'], + require => [ Group['backupninjas'], File["$real_dir"] ], tag => "$real_backuptag" } } @@ -112,7 +112,7 @@ class backupninja::server { managehome => true, shell => "/bin/sh", password => '*', - require => Group['backupninjas'], + require => [ Group['backupninjas'], File["$real_dir"] ], tag => "$real_backuptag" } } -- cgit v1.2.3 From 42150a822c5e0718644a83a39d3c368e9631bd65 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Sat, 6 Dec 2008 19:48:05 -0500 Subject: fix typo in mysql commit --- manifests/mysql.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/mysql.pp b/manifests/mysql.pp index 08af103..6241519 100644 --- a/manifests/mysql.pp +++ b/manifests/mysql.pp @@ -21,7 +21,7 @@ define backupninja::mysql( $vsname = false) { - $real_config_file = $configfile ? { + $real_configfile = $configfile ? { true => "/etc/mysql/debian.cnf", default => $configfile, } -- cgit v1.2.3 From 5b9c6255b87f0cf029320973053e4f7ad98063f0 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Sat, 6 Dec 2008 19:49:22 -0500 Subject: replace the directory parameter by a home parameter the directory is now /rdiff-backup to avoid rdiff-backup overwriting the .ssh dir at every run --- manifests/rdiff.pp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index e3964d0..ed1ea55 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -16,7 +16,7 @@ # directories. # define backupninja::rdiff( - $order = 90, $ensure = present, $user = false, $directory = false, $host = false, + $order = 90, $ensure = present, $user = false, $home = false, $host = false, $type = 'local', $exclude = [ "/home/*/.gnupg", "/home/*/.local/share/Trash", "/home/*/.Trash", "/home/*/.thumbnails", "/home/*/.beagle", "/home/*/.aMule", @@ -27,6 +27,7 @@ define backupninja::rdiff( $ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, $backuptag = false) { + $directory = "$home/rdiff-backup/" include backupninja::client case $type { 'remote': { @@ -34,7 +35,7 @@ define backupninja::rdiff( backupninja::server::sandbox { - "${user}-${name}": user => $user, host => $host, dir => $directory, + "${user}-${name}": user => $user, host => $host, dir => $home, manage_ssh_dir => $ssh_dir_manage, ssh_dir => $ssh_dir, authorized_keys_file => $authorized_keys_file, installuser => $installuser, backuptag => $backuptag -- cgit v1.2.3 From f51344acc8a55fe2dd0b9b17331e913d6ef723d0 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Sat, 6 Dec 2008 19:56:45 -0500 Subject: fix variable instanciation in template --- templates/rdiff.conf.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/rdiff.conf.erb b/templates/rdiff.conf.erb index 5e319a2..f5548e4 100644 --- a/templates/rdiff.conf.erb +++ b/templates/rdiff.conf.erb @@ -29,7 +29,7 @@ type = local [dest] <% %w{type host directory user sshoptions}.each do |v| - if has_variable?(v) - -%><%= v + ' = ' + get_instance_var("@#{v}") + "\n" %><% + if @scope.lookupvar(v) + -%><%= v + ' = ' + @scope.lookupvar(v) + "\n" %><% end end -%> -- cgit v1.2.3 From 1bf7ed061e334a6b622161d4827181e20c471f9b Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Thu, 11 Dec 2008 09:07:15 -0500 Subject: fix user initialisation. without this i was getting: Could not retrieve catalog: Puppet::Parser::AST::Resource failed with error ArgumentError: Duplicate definition: User[false] is already defined in file /etc/puppet/modules/backupninja/manifests/server.pp at line 103; cannot redefine at /etc/puppet/modules/backupninja/manifests/server.pp:103 on node alexandria.koumbit.net also add rsync and rdiff-backup on the backup server to make those methods work out of the box --- manifests/server.pp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/manifests/server.pp b/manifests/server.pp index e4298ef..bf7e788 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -26,6 +26,8 @@ class backupninja::server { User <<| tag == "backupninja-$real_backupserver_tag" |>> File <<| tag == "backupninja-$real_backupserver_tag" |>> + package { [ "rsync", "rdiff-backup" ]: ensure => installed } + # this define allows nodes to declare a remote backup sandbox, that have to # get created on the server define sandbox( @@ -34,7 +36,7 @@ class backupninja::server { $gid = "backupninjas", $backuptag = false) { - $real_user = $name ? { + $real_user = $user ? { false => $name, default => $user, '' => $name, @@ -66,7 +68,7 @@ class backupninja::server { @@file { "$real_dir": ensure => directory, - mode => 0750, owner => $user, group => 0, + mode => 0750, owner => $real_user, group => 0, tag => "$real_backuptag", } case $installuser { @@ -75,7 +77,7 @@ class backupninja::server { true: { @@file { "${real_ssh_dir}": ensure => directory, - mode => 0700, owner => $user, group => 0, + mode => 0700, owner => $real_user, group => 0, require => File["$real_dir"], tag => "$real_backuptag", } @@ -84,13 +86,13 @@ class backupninja::server { @@file { "${real_ssh_dir}/${real_authorized_keys_file}": ensure => present, mode => 0644, owner => 0, group => 0, - source => "$real_backupkeys/${user}_id_rsa.pub", + source => "$real_backupkeys/${real_user}_id_rsa.pub", require => File["${real_ssh_dir}"], tag => "$real_backuptag", } case $uid { false: { - @@user { "$user": + @@user { "$real_user": ensure => "present", gid => "$gid", comment => "$name backup sandbox", @@ -103,7 +105,7 @@ class backupninja::server { } } default: { - @@user { "$user": + @@user { "$real_user": ensure => "present", uid => "$uid", gid => "$gid", -- cgit v1.2.3 From f55b76f4aafbea8e5a42ea7ff0dfe8ca9ff10bec Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Thu, 11 Dec 2008 10:12:24 -0500 Subject: allow arbitrary keyfiles to be distributed alongside the rdiff plugin --- manifests/rdiff.pp | 4 ++-- manifests/server.pp | 30 ++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index ed1ea55..4abc9b2 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -24,7 +24,7 @@ define backupninja::rdiff( $include = [ "/var/spool/cron/crontabs", "/var/backups", "/etc", "/root", "/home", "/usr/local/*bin", "/var/lib/dpkg/status*" ], $vsinclude = false, $keep = 30, $sshoptions = false, $options = false, $ssh_dir_manage = true, - $ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, + $ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, $key = false, $backuptag = false) { $directory = "$home/rdiff-backup/" @@ -36,7 +36,7 @@ define backupninja::rdiff( backupninja::server::sandbox { "${user}-${name}": user => $user, host => $host, dir => $home, - manage_ssh_dir => $ssh_dir_manage, ssh_dir => $ssh_dir, + manage_ssh_dir => $ssh_dir_manage, ssh_dir => $ssh_dir, key => $key, authorized_keys_file => $authorized_keys_file, installuser => $installuser, backuptag => $backuptag } diff --git a/manifests/server.pp b/manifests/server.pp index bf7e788..6033249 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -25,6 +25,7 @@ class backupninja::server { User <<| tag == "backupninja-$real_backupserver_tag" |>> File <<| tag == "backupninja-$real_backupserver_tag" |>> + Ssh_authorized_key <<| tag == "backupninja-$real_backupserver_tag" |>> package { [ "rsync", "rdiff-backup" ]: ensure => installed } @@ -32,7 +33,7 @@ class backupninja::server { # get created on the server define sandbox( $user = false, $host = false, $installuser = true, $dir = false, $manage_ssh_dir = true, - $ssh_dir = false, $authorized_keys_file = false, $backupkeys = false, $uid = false, + $ssh_dir = false, $authorized_keys_file = false, $key = false, $key_type = 'ssh-dss', $backupkeys = false, $uid = false, $gid = "backupninjas", $backuptag = false) { @@ -83,13 +84,26 @@ class backupninja::server { } } } - @@file { "${real_ssh_dir}/${real_authorized_keys_file}": - ensure => present, - mode => 0644, owner => 0, group => 0, - source => "$real_backupkeys/${real_user}_id_rsa.pub", - require => File["${real_ssh_dir}"], - tag => "$real_backuptag", - } + case $key { + false: { + @@file { "${real_ssh_dir}/${real_authorized_keys_file}": + ensure => present, + mode => 0644, owner => 0, group => 0, + source => "$real_backupkeys/${real_user}_id_rsa.pub", + require => File["${real_ssh_dir}"], + tag => "$real_backuptag", + } + } + default: { + @@ssh_authorized_key{ $real_user: + type => $key_type, + key => $key, + user => $real_user, + target => "${real_ssh_dir}/${real_authorized_keys_file}", + tag => "$real_backuptag", + } + } + } case $uid { false: { @@user { "$real_user": -- cgit v1.2.3 From f1b2351569d450a15c06529ec3dcfbaca8365e33 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 6 Jan 2009 16:47:58 -0500 Subject: cosmetic changes --- templates/checkbackups.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 templates/checkbackups.sh diff --git a/templates/checkbackups.sh b/templates/checkbackups.sh new file mode 100755 index 0000000..8d143a3 --- /dev/null +++ b/templates/checkbackups.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# This script is designed to check a backup directory populated with +# subdirectories named after hosts, within which there are backups of various +# types. +# +# Example: +# /home/backup: +# foo.example.com +# +# foo.example.com: +# rdiff-backup .ssh +# +# rdiff-backup: +# root home rdiff-backup-data usr var +# +# There are heuristics to determine the backup type. Currently, the following +# types are supported: +# +# rdiff-backup: assumes there is a rdiff-backup/rdiff-backup-data/backup.log file +# duplicity: assumes there is a dup subdirectory, checks the latest file +# dump files: assumes there is a dump subdirectory, checks the latest file +# +# This script returns output suitable for send_nsca to send the results to +# nagios and should therefore be used like this: +# +# checkbackups.sh | send_nsca -H nagios.example.com + +# XXX: taken from utils.sh from nagios-plugins-basic +STATE_OK=0 +STATE_WARNING=1 +STATE_CRITICAL=2 +STATE_UNKNOWN=3 +STATE_DEPENDENT=4 + +backupdir="<%= real_backupdir -%>" + +# XXX: this should be a complete backup registry instead +hosts=`ls $backupdir` +stampfile=$backupdir/.stamp + +cd $backupdir +for host in $hosts; do + flag="" + type="unknown" + if [ -d $host ]; then + # guess the backup type and find a proper stamp file to compare + # XXX: this doesn't check if the backup was actually successful + # XXX: the backup type should be part of the machine registry + if [ -d $host/rdiff-backup ]; then + flag=$host/rdiff-backup/rdiff-backup-data/backup.log + type="rdiff" + elif [ -d $host/dump ]; then + flag="$host/dump/`ls -tr $host/dump | tail -1`" + type="dump" + elif [ -d $host/dup ]; then + flag="$host/dup/`ls -tr $host/dup | tail -1`" + type="duplicity" + else + printf "$host\tbackups\t$STATE_UNKNOWN\tUNKNOWN unknown system\n" + continue + fi + touch -t `date +%Y%m%d0000.00` $stampfile + date=`ls -l $flag | awk '{print $6 " " $7}'` + if [ $flag -nt $stampfile ]; then + printf "$host\tbackups\t$STATE_OK\tOK timestamp $date\n" + else + printf "$host\tbackups\t$STATE_CRITICAL\tCRITICAL timestamp $date\n" + fi + else + printf "$host\tbackups\t$STATE_UNKNOWN\tUNKNOWN timestamp no directory\n" + fi +done -- cgit v1.2.3 From b27f528d43b40105af2e34d066d2f54c5e6a1dcb Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 6 Jan 2009 16:49:02 -0500 Subject: send the fqdn, not the specified host, to the sandbox so that it knows for which host it's being configured --- manifests/rdiff.pp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index 4abc9b2..0228a06 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -27,6 +27,11 @@ define backupninja::rdiff( $ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, $key = false, $backuptag = false) { + $real_backuptag = $backuptag ? { + false => $host, + default => $backuptag + } + $directory = "$home/rdiff-backup/" include backupninja::client case $type { @@ -35,10 +40,10 @@ define backupninja::rdiff( backupninja::server::sandbox { - "${user}-${name}": user => $user, host => $host, dir => $home, + "${user}-${name}": user => $user, host => $fqdn, dir => $home, manage_ssh_dir => $ssh_dir_manage, ssh_dir => $ssh_dir, key => $key, authorized_keys_file => $authorized_keys_file, installuser => $installuser, - backuptag => $backuptag + backuptag => $real_backuptag } backupninja::client::key -- cgit v1.2.3 From 392438512bf1fa82cbac491596a7387b6cb43e86 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 6 Jan 2009 16:49:37 -0500 Subject: add checkbackups cron job, fix multiple instances of passive service for manually specified sandboxes --- manifests/server.pp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/manifests/server.pp b/manifests/server.pp index 6033249..e4ed80a 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -23,6 +23,20 @@ class backupninja::server { mode => 0710, owner => root, group => "backupninjas" } + file { "/usr/local/bin/checkbackups": + ensure => "present", + content => template("backupninja/checkbackups.sh"), + mode => 0755, owner => root, group => root, + } + + cron { checkbackups: + command => "/usr/local/bin/checkbackups.sh | /usr/sbin/send_nsca -H nagios.koumbit.net -c /etc/send_nsca.cfg", + user => "root", + hour => 8, + minute => 0, + require => [ File["/usr/local/bin/checkbackups"], Package['nsca'] ] + } + User <<| tag == "backupninja-$real_backupserver_tag" |>> File <<| tag == "backupninja-$real_backupserver_tag" |>> Ssh_authorized_key <<| tag == "backupninja-$real_backupserver_tag" |>> @@ -63,10 +77,13 @@ class backupninja::server { default => $authorized_keys_file, } $real_backuptag = $backuptag ? { - false => "backupninja-$real_host", + false => "backupninja-$fqdn", default => $backuptag, } + # configure a passive service check for backups + nagios2::passive_service { "backups-$real_host": nagios2_host_name => $real_host, nagios2_description => 'backups' } + @@file { "$real_dir": ensure => directory, mode => 0750, owner => $real_user, group => 0, -- cgit v1.2.3 From 7a2b7798c8680499ddcb7bd57433d2a3f981e924 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Thu, 8 Jan 2009 17:57:33 -0500 Subject: run the nagios checks more regularly --- manifests/server.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/server.pp b/manifests/server.pp index e4ed80a..4284ffa 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -32,8 +32,8 @@ class backupninja::server { cron { checkbackups: command => "/usr/local/bin/checkbackups.sh | /usr/sbin/send_nsca -H nagios.koumbit.net -c /etc/send_nsca.cfg", user => "root", - hour => 8, - minute => 0, + hour => "8-23", + minute => 59, require => [ File["/usr/local/bin/checkbackups"], Package['nsca'] ] } -- cgit v1.2.3 From 55c60873a76c0e95737785a5d78516f9beef7f33 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 13 Jan 2009 16:08:28 -0500 Subject: rewrite nagios check scripts in perl --- files/checkbackups.pl | 101 ++++++++++++++++++++++++++++++++++++++++++++++ manifests/server.pp | 4 +- templates/checkbackups.sh | 73 --------------------------------- 3 files changed, 103 insertions(+), 75 deletions(-) create mode 100755 files/checkbackups.pl delete mode 100755 templates/checkbackups.sh diff --git a/files/checkbackups.pl b/files/checkbackups.pl new file mode 100755 index 0000000..24632d1 --- /dev/null +++ b/files/checkbackups.pl @@ -0,0 +1,101 @@ +#!/usr/bin/perl -w + +# This script is designed to check a backup directory populated with +# subdirectories named after hosts, within which there are backups of various +# types. +# +# Example: +# /home/backup: +# foo.example.com +# +# foo.example.com: +# rdiff-backup .ssh +# +# rdiff-backup: +# root home rdiff-backup-data usr var +# +# There are heuristics to determine the backup type. Currently, the following +# types are supported: +# +# rdiff-backup: assumes there is a rdiff-backup/rdiff-backup-data/backup.log file +# duplicity: assumes there is a dup subdirectory, checks the latest file +# dump files: assumes there is a dump subdirectory, checks the latest file +# +# This script returns output suitable for send_nsca to send the results to +# nagios and should therefore be used like this: +# +# checkbackups.sh | send_nsca -H nagios.example.com + +use Getopt::Std; + +# XXX: taken from utils.sh from nagios-plugins-basic +my $STATE_OK=0; +my $STATE_WARNING=1; +my $STATE_CRITICAL=2; +my $STATE_UNKNOWN=3; +my $STATE_DEPENDENT=4; + +our $opt_d = "/backup"; +our $opt_c = 48 * 60 * 60; +our $opt_w = 24 * 60 * 60; + +if (!getopts('d:c:w:')) { + print < ] [ -c ] [ -w ] +EOF + ; + exit(); +} + +my $backupdir= $opt_d; +my $crit = $opt_c; +my $warn = $opt_w; + +# XXX: this should be a complete backup registry instead +my @hosts=qx{ls $backupdir}; + +chdir($backupdir); +foreach my $host (@hosts) { + chomp($host); + my $flag=""; + my $type="unknown"; + if (-d $host) { + # guess the backup type and find a proper stamp file to compare + # XXX: this doesn't check if the backup was actually successful + # XXX: the backup type should be part of the machine registry + if (-d "$host/rdiff-backup") { + $flag="$host/rdiff-backup/rdiff-backup-data/backup.log"; + $type="rdiff"; + } elsif (-d "$host/dump") { + $flag="$host/dump/" . `ls -tr $host/dump | tail -1`; + chomp($flag); + $type="dump"; + } elsif (-d "$host/dup") { + $flag="$host/dup"; + $type="duplicity"; + } else { + printf "$host\tbackups\t$STATE_UNKNOWN\tunknown system\n"; + next; + } + my @stats = stat($flag); + if (not @stats) { + printf "$host\tbackups\t$STATE_UNKNOWN\tcannot stat flag $flag\n"; + next; + } + my $t = time(); + my $delta = $t - $stats[9]; + my $state = $STATE_UNKNOWN; + if ($delta > $crit) { + $state = $STATE_CRITICAL; + } elsif ($delta > $warn) { + $state = $STATE_WARNING; + } elsif ($delta >= 0) { + $state = $STATE_OK; + } + print "$host\t"; + print "backups\t$state"; + print "\t$delta seconds old\n"; + } else { + printf "$host\tbackups\t$STATE_UNKNOWN\tno directory\n"; + } +} diff --git a/manifests/server.pp b/manifests/server.pp index 4284ffa..9b08b22 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -25,12 +25,12 @@ class backupninja::server { file { "/usr/local/bin/checkbackups": ensure => "present", - content => template("backupninja/checkbackups.sh"), + source => "puppet://$servername/backupninja/checkbackups.pl", mode => 0755, owner => root, group => root, } cron { checkbackups: - command => "/usr/local/bin/checkbackups.sh | /usr/sbin/send_nsca -H nagios.koumbit.net -c /etc/send_nsca.cfg", + command => "/usr/local/bin/checkbackups -d $real_backupdir | /usr/sbin/send_nsca -H nagios.koumbit.net -c /etc/send_nsca.cfg | grep -v 'sent to host successfully'", user => "root", hour => "8-23", minute => 59, diff --git a/templates/checkbackups.sh b/templates/checkbackups.sh deleted file mode 100755 index 8d143a3..0000000 --- a/templates/checkbackups.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh - -# This script is designed to check a backup directory populated with -# subdirectories named after hosts, within which there are backups of various -# types. -# -# Example: -# /home/backup: -# foo.example.com -# -# foo.example.com: -# rdiff-backup .ssh -# -# rdiff-backup: -# root home rdiff-backup-data usr var -# -# There are heuristics to determine the backup type. Currently, the following -# types are supported: -# -# rdiff-backup: assumes there is a rdiff-backup/rdiff-backup-data/backup.log file -# duplicity: assumes there is a dup subdirectory, checks the latest file -# dump files: assumes there is a dump subdirectory, checks the latest file -# -# This script returns output suitable for send_nsca to send the results to -# nagios and should therefore be used like this: -# -# checkbackups.sh | send_nsca -H nagios.example.com - -# XXX: taken from utils.sh from nagios-plugins-basic -STATE_OK=0 -STATE_WARNING=1 -STATE_CRITICAL=2 -STATE_UNKNOWN=3 -STATE_DEPENDENT=4 - -backupdir="<%= real_backupdir -%>" - -# XXX: this should be a complete backup registry instead -hosts=`ls $backupdir` -stampfile=$backupdir/.stamp - -cd $backupdir -for host in $hosts; do - flag="" - type="unknown" - if [ -d $host ]; then - # guess the backup type and find a proper stamp file to compare - # XXX: this doesn't check if the backup was actually successful - # XXX: the backup type should be part of the machine registry - if [ -d $host/rdiff-backup ]; then - flag=$host/rdiff-backup/rdiff-backup-data/backup.log - type="rdiff" - elif [ -d $host/dump ]; then - flag="$host/dump/`ls -tr $host/dump | tail -1`" - type="dump" - elif [ -d $host/dup ]; then - flag="$host/dup/`ls -tr $host/dup | tail -1`" - type="duplicity" - else - printf "$host\tbackups\t$STATE_UNKNOWN\tUNKNOWN unknown system\n" - continue - fi - touch -t `date +%Y%m%d0000.00` $stampfile - date=`ls -l $flag | awk '{print $6 " " $7}'` - if [ $flag -nt $stampfile ]; then - printf "$host\tbackups\t$STATE_OK\tOK timestamp $date\n" - else - printf "$host\tbackups\t$STATE_CRITICAL\tCRITICAL timestamp $date\n" - fi - else - printf "$host\tbackups\t$STATE_UNKNOWN\tUNKNOWN timestamp no directory\n" - fi -done -- cgit v1.2.3 From a0ed0c866d139127393223e490b85709e6fdc50b Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Wed, 14 Jan 2009 19:02:53 -0500 Subject: default backup tag to fqdn, not specified host --- manifests/rdiff.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index 0228a06..ee99821 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -28,7 +28,7 @@ define backupninja::rdiff( $backuptag = false) { $real_backuptag = $backuptag ? { - false => $host, + false => $fqdn, default => $backuptag } @@ -40,7 +40,7 @@ define backupninja::rdiff( backupninja::server::sandbox { - "${user}-${name}": user => $user, host => $fqdn, dir => $home, + "${user}-${name}": user => $user, host => $host, dir => $home, manage_ssh_dir => $ssh_dir_manage, ssh_dir => $ssh_dir, key => $key, authorized_keys_file => $authorized_keys_file, installuser => $installuser, backuptag => $real_backuptag -- cgit v1.2.3 From b6bf47ef89024ae39f9fe25370554c4ea46914bb Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Wed, 14 Jan 2009 19:03:06 -0500 Subject: fix sandbox dependencies --- manifests/server.pp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/manifests/server.pp b/manifests/server.pp index 9b08b22..3978f3a 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -96,7 +96,7 @@ class backupninja::server { @@file { "${real_ssh_dir}": ensure => directory, mode => 0700, owner => $real_user, group => 0, - require => File["$real_dir"], + require => [User[$real_user], File["$real_dir"]], tag => "$real_backuptag", } } @@ -118,6 +118,7 @@ class backupninja::server { user => $real_user, target => "${real_ssh_dir}/${real_authorized_keys_file}", tag => "$real_backuptag", + require => User[$real_user], } } } @@ -131,7 +132,7 @@ class backupninja::server { managehome => true, shell => "/bin/sh", password => '*', - require => [ Group['backupninjas'], File["$real_dir"] ], + require => Group['backupninjas'], tag => "$real_backuptag" } } @@ -145,7 +146,7 @@ class backupninja::server { managehome => true, shell => "/bin/sh", password => '*', - require => [ Group['backupninjas'], File["$real_dir"] ], + require => Group['backupninjas'], tag => "$real_backuptag" } } -- cgit v1.2.3 From f6cdb278a75088a38b18a565563e7900321b925b Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Wed, 14 Jan 2009 22:42:50 -0500 Subject: revert part of last commit: the backuptag is really based on the host provided to the rdiff command and the host provided to the sandbox is the fqdn of the server --- manifests/rdiff.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index ee99821..0228a06 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -28,7 +28,7 @@ define backupninja::rdiff( $backuptag = false) { $real_backuptag = $backuptag ? { - false => $fqdn, + false => $host, default => $backuptag } @@ -40,7 +40,7 @@ define backupninja::rdiff( backupninja::server::sandbox { - "${user}-${name}": user => $user, host => $host, dir => $home, + "${user}-${name}": user => $user, host => $fqdn, dir => $home, manage_ssh_dir => $ssh_dir_manage, ssh_dir => $ssh_dir, key => $key, authorized_keys_file => $authorized_keys_file, installuser => $installuser, backuptag => $real_backuptag -- cgit v1.2.3 From 9f61f6a39063737ec690e91c9ff35ff4ee391f74 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Sat, 17 Jan 2009 18:14:02 -0500 Subject: upgrade backupninja to new testing version --- manifests/client.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/client.pp b/manifests/client.pp index c98bced..66dbd1c 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -32,7 +32,7 @@ class backupninja::client { default => $ssh_dir_manage } package { 'backupninja': - ensure => '0.9.6-3'; + ensure => '0.9.6-4'; } file { $configdir: ensure => directory -- cgit v1.2.3 From e7009976eeab68bb1a68817881bcb1936960157d Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Sat, 17 Jan 2009 18:24:25 -0500 Subject: fix resource tag exported from rdiff resources, install rdiff in the rdiff-backup define --- manifests/rdiff.pp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index 0228a06..9c81289 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -28,7 +28,7 @@ define backupninja::rdiff( $backuptag = false) { $real_backuptag = $backuptag ? { - false => $host, + false => "backupninja-$host", default => $backuptag } @@ -61,5 +61,6 @@ define backupninja::rdiff( mode => 0600, require => File["${backupninja::client::configdir}"] } + package { "rdiff-backup": ensure => installed } } -- cgit v1.2.3 From 981c43068254a2c49a677bb7c66c61c5c0f99943 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Fri, 17 Apr 2009 13:01:26 -0400 Subject: try to refactor to detect vserver backups --- files/checkbackups.pl | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index 24632d1..adc4379 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -59,6 +59,8 @@ foreach my $host (@hosts) { chomp($host); my $flag=""; my $type="unknown"; + my @vservers = (); + my $state = $STATE_UNKNOWN; if (-d $host) { # guess the backup type and find a proper stamp file to compare # XXX: this doesn't check if the backup was actually successful @@ -66,6 +68,11 @@ foreach my $host (@hosts) { if (-d "$host/rdiff-backup") { $flag="$host/rdiff-backup/rdiff-backup-data/backup.log"; $type="rdiff"; + $vserver_dir = "$host/rdiff-backup/var/lib/vservers"; + if (opendir(DIR, $vserver_dir)) { + @vservers = grep { /^\./ && -f "$vserver_dir/$_" } readdir(DIR); + closedir DIR; + } } elsif (-d "$host/dump") { $flag="$host/dump/" . `ls -tr $host/dump | tail -1`; chomp($flag); @@ -74,17 +81,16 @@ foreach my $host (@hosts) { $flag="$host/dup"; $type="duplicity"; } else { - printf "$host\tbackups\t$STATE_UNKNOWN\tunknown system\n"; + $message = "unknown system"; next; } my @stats = stat($flag); if (not @stats) { - printf "$host\tbackups\t$STATE_UNKNOWN\tcannot stat flag $flag\n"; + $message = "cannot stat flag $flag"; next; } my $t = time(); my $delta = $t - $stats[9]; - my $state = $STATE_UNKNOWN; if ($delta > $crit) { $state = $STATE_CRITICAL; } elsif ($delta > $warn) { @@ -92,10 +98,13 @@ foreach my $host (@hosts) { } elsif ($delta >= 0) { $state = $STATE_OK; } - print "$host\t"; - print "backups\t$state"; - print "\t$delta seconds old\n"; + $message = "$delta seconds old"; } else { - printf "$host\tbackups\t$STATE_UNKNOWN\tno directory\n"; + $message = "no directory"; + } +} continue { + printf "$host\tbackups\t$state\t$message\n"; + foreach my $vserver (@vservers) { + printf "$vserver\tbackups\t$state\t$message\n"; } } -- cgit v1.2.3 From 9aa5fb318ffe3bf976d4e456c2754ca6b97dc9e8 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Fri, 17 Apr 2009 13:01:54 -0400 Subject: detect multiple vserver locations --- files/checkbackups.pl | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index adc4379..f46920b 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -35,6 +35,11 @@ my $STATE_CRITICAL=2; my $STATE_UNKNOWN=3; my $STATE_DEPENDENT=4; +# gross hack: we look into subdirs to find vservers +my @vserver_dirs = qw{/var/lib/vservers /vservers}; +# even worse: hardcode a suffix to the vserver name to get a FQDN +my $dom_sufx = ".koumbit.net"; + our $opt_d = "/backup"; our $opt_c = 48 * 60 * 60; our $opt_w = 24 * 60 * 60; @@ -55,12 +60,14 @@ my $warn = $opt_w; my @hosts=qx{ls $backupdir}; chdir($backupdir); -foreach my $host (@hosts) { +my ($state, $message, @vservers, $host); +foreach $host (@hosts) { chomp($host); my $flag=""; my $type="unknown"; - my @vservers = (); - my $state = $STATE_UNKNOWN; + @vservers = (); + $state = $STATE_UNKNOWN; + $message = "???"; if (-d $host) { # guess the backup type and find a proper stamp file to compare # XXX: this doesn't check if the backup was actually successful @@ -68,10 +75,12 @@ foreach my $host (@hosts) { if (-d "$host/rdiff-backup") { $flag="$host/rdiff-backup/rdiff-backup-data/backup.log"; $type="rdiff"; - $vserver_dir = "$host/rdiff-backup/var/lib/vservers"; - if (opendir(DIR, $vserver_dir)) { - @vservers = grep { /^\./ && -f "$vserver_dir/$_" } readdir(DIR); - closedir DIR; + foreach my $vserver_dir (@vserver_dirs) { + $dir = "$host/rdiff-backup$vserver_dir"; + if (opendir(DIR, $dir)) { + @vservers = grep { /^[^\.]/ && -d "$dir/$_" } readdir(DIR); + closedir DIR; + } } } elsif (-d "$host/dump") { $flag="$host/dump/" . `ls -tr $host/dump | tail -1`; @@ -105,6 +114,6 @@ foreach my $host (@hosts) { } continue { printf "$host\tbackups\t$state\t$message\n"; foreach my $vserver (@vservers) { - printf "$vserver\tbackups\t$state\t$message\n"; + printf "$vserver$dom_sufx\tbackups\t$state\t$message\n"; } } -- cgit v1.2.3 From 0c604312144f476bb35a9539e351daefb3f05a6c Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Fri, 17 Apr 2009 13:08:53 -0400 Subject: note which is the parent --- files/checkbackups.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index f46920b..df73ceb 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -114,6 +114,6 @@ foreach $host (@hosts) { } continue { printf "$host\tbackups\t$state\t$message\n"; foreach my $vserver (@vservers) { - printf "$vserver$dom_sufx\tbackups\t$state\t$message\n"; + printf "$vserver$dom_sufx\tbackups\t$state\t$message, same as parent: $host\n"; } } -- cgit v1.2.3 From 3c80f2328ed686b3b9565a4cced50e3e91c6af1b Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Fri, 17 Apr 2009 13:09:26 -0400 Subject: drop the dom_sufx hack, calculate based on the parent's domain instead --- files/checkbackups.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index df73ceb..5e75b85 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -37,8 +37,6 @@ my $STATE_DEPENDENT=4; # gross hack: we look into subdirs to find vservers my @vserver_dirs = qw{/var/lib/vservers /vservers}; -# even worse: hardcode a suffix to the vserver name to get a FQDN -my $dom_sufx = ".koumbit.net"; our $opt_d = "/backup"; our $opt_c = 48 * 60 * 60; @@ -113,6 +111,8 @@ foreach $host (@hosts) { } } continue { printf "$host\tbackups\t$state\t$message\n"; + my @dom_sufx = split(/\./, $host); + my $dom_sufx = join('.', @dom_sufx[1,-1]); foreach my $vserver (@vservers) { printf "$vserver$dom_sufx\tbackups\t$state\t$message, same as parent: $host\n"; } -- cgit v1.2.3 From 6ed0d0399c42187ec3ed0ef54c39a9c1b70aff91 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Mon, 27 Apr 2009 15:02:03 -0400 Subject: add missing comma --- files/checkbackups.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index 5e75b85..5748f75 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -114,6 +114,6 @@ foreach $host (@hosts) { my @dom_sufx = split(/\./, $host); my $dom_sufx = join('.', @dom_sufx[1,-1]); foreach my $vserver (@vservers) { - printf "$vserver$dom_sufx\tbackups\t$state\t$message, same as parent: $host\n"; + printf "$vserver.$dom_sufx\tbackups\t$state\t$message, same as parent: $host\n"; } } -- cgit v1.2.3 From bc2b6bd0e4222a6477ae806a5329480a3ecf873b Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Mon, 27 Apr 2009 15:21:21 -0400 Subject: add backups servicegroup, put rdiff in a seperate class so we can override --- manifests/server.pp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/manifests/server.pp b/manifests/server.pp index 3978f3a..77fc33d 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -41,7 +41,8 @@ class backupninja::server { File <<| tag == "backupninja-$real_backupserver_tag" |>> Ssh_authorized_key <<| tag == "backupninja-$real_backupserver_tag" |>> - package { [ "rsync", "rdiff-backup" ]: ensure => installed } + package { "rsync": ensure => installed } + include backupninja::rdiff-installed # this define allows nodes to declare a remote backup sandbox, that have to # get created on the server @@ -82,7 +83,7 @@ class backupninja::server { } # configure a passive service check for backups - nagios2::passive_service { "backups-$real_host": nagios2_host_name => $real_host, nagios2_description => 'backups' } + nagios2::passive_service { "backups-$real_host": nagios2_host_name => $real_host, nagios2_description => 'backups', servicegroups => "backups" } @@file { "$real_dir": ensure => directory, -- cgit v1.2.3 From 245e6bde0c4c4a24f6b169aa88aaf0ff038241ac Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Mon, 27 Apr 2009 15:22:11 -0400 Subject: always use force, use backports for rdiff-backup in etch so we always use lenny's version --- manifests/rdiff.pp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index 9c81289..e3e429b 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -23,7 +23,7 @@ define backupninja::rdiff( "/home/*/gtk-gnutella-downloads" ], $include = [ "/var/spool/cron/crontabs", "/var/backups", "/etc", "/root", "/home", "/usr/local/*bin", "/var/lib/dpkg/status*" ], - $vsinclude = false, $keep = 30, $sshoptions = false, $options = false, $ssh_dir_manage = true, + $vsinclude = false, $keep = 30, $sshoptions = false, $options = '--force', $ssh_dir_manage = true, $ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, $key = false, $backuptag = false) { @@ -61,6 +61,14 @@ define backupninja::rdiff( mode => 0600, require => File["${backupninja::client::configdir}"] } - package { "rdiff-backup": ensure => installed } + include backupninja::rdiff-installed +} + +class backupninja::rdiff-installed { + case $lsbdistcodename { + "etch": { $version = "1.2.5-1~bpo40+1" } + default: { $version = "installed" } + } + package { "rdiff-backup": ensure => $version } } -- cgit v1.2.3 From e7ac16329b76d8a17fa7b247d55d3c3f7c9f2e10 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 16 Jun 2009 10:51:29 -0400 Subject: parse rdiff-backup logfile for the last real successful backup instead of just relying on the backup logfile timestamp --- files/checkbackups.pl | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index 5748f75..2084e86 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -41,10 +41,11 @@ my @vserver_dirs = qw{/var/lib/vservers /vservers}; our $opt_d = "/backup"; our $opt_c = 48 * 60 * 60; our $opt_w = 24 * 60 * 60; +our $opt_v = 0; -if (!getopts('d:c:w:')) { +if (!getopts('d:c:w:v')) { print < ] [ -c ] [ -w ] +Usage: $0 [ -d ] [ -c ] [ -w ] -v EOF ; exit(); @@ -63,16 +64,33 @@ foreach $host (@hosts) { chomp($host); my $flag=""; my $type="unknown"; + my $extra_msg=""; @vservers = (); $state = $STATE_UNKNOWN; $message = "???"; if (-d $host) { # guess the backup type and find a proper stamp file to compare - # XXX: this doesn't check if the backup was actually successful # XXX: the backup type should be part of the machine registry + my $last_bak; if (-d "$host/rdiff-backup") { $flag="$host/rdiff-backup/rdiff-backup-data/backup.log"; $type="rdiff"; + if (open(FLAG, $flag)) { + while () { + if (/StartTime ([0-9]*).[0-9]* \((.*)\)/) { + $last_bak = $1; + $extra_msg = ' [backup.log]'; + $opt_v && print STDERR "found timestamp $1 ($2) in backup.log\n"; + } + } + if (!$last_bak) { + $message = "cannot parse backup.log for a valid timestamp"; + next; + } + } else { + $opt_v && print STDERR "cannot open backup.log\n"; + } + close(FLAG); foreach my $vserver_dir (@vserver_dirs) { $dir = "$host/rdiff-backup$vserver_dir"; if (opendir(DIR, $dir)) { @@ -81,23 +99,28 @@ foreach $host (@hosts) { } } } elsif (-d "$host/dump") { + # XXX: this doesn't check backup consistency $flag="$host/dump/" . `ls -tr $host/dump | tail -1`; chomp($flag); $type="dump"; } elsif (-d "$host/dup") { + # XXX: this doesn't check backup consistency $flag="$host/dup"; $type="duplicity"; } else { $message = "unknown system"; next; } - my @stats = stat($flag); - if (not @stats) { - $message = "cannot stat flag $flag"; - next; + if (!defined($last_bak)) { + my @stats = stat($flag); + if (not @stats) { + $message = "cannot stat flag $flag"; + next; + } + $last_bak = $stats[9]; } my $t = time(); - my $delta = $t - $stats[9]; + my $delta = $t - $last_bak; if ($delta > $crit) { $state = $STATE_CRITICAL; } elsif ($delta > $warn) { @@ -105,7 +128,7 @@ foreach $host (@hosts) { } elsif ($delta >= 0) { $state = $STATE_OK; } - $message = "$delta seconds old"; + $message = "$delta seconds old$extra_msg"; } else { $message = "no directory"; } -- cgit v1.2.3 From 77ca6deb7a3a194ffeeb4c3a5cf0855bd06a0ae9 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 16 Jun 2009 10:52:14 -0400 Subject: add extras flag to add arbitrary options to rdiff configuration --- manifests/rdiff.pp | 2 +- templates/rdiff.conf.erb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index e3e429b..8e0e769 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -25,7 +25,7 @@ define backupninja::rdiff( "/home", "/usr/local/*bin", "/var/lib/dpkg/status*" ], $vsinclude = false, $keep = 30, $sshoptions = false, $options = '--force', $ssh_dir_manage = true, $ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, $key = false, - $backuptag = false) + $backuptag = false, $extras = false) { $real_backuptag = $backuptag ? { false => "backupninja-$host", diff --git a/templates/rdiff.conf.erb b/templates/rdiff.conf.erb index 0e19125..99bda4e 100644 --- a/templates/rdiff.conf.erb +++ b/templates/rdiff.conf.erb @@ -5,6 +5,8 @@ <%= 'options = ' + options if options %> +<%= extras if extras %> + [source] type = local <%= 'keep = ' + keep if keep %> -- cgit v1.2.3 From 1ac4ac4eddd76e3fb55ab6c0b932ce9a540bf5c6 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 16 Jun 2009 22:34:39 -0400 Subject: the rdiff handler requires rsync to be installed on the node, include it --- manifests/maildir.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/maildir.pp b/manifests/maildir.pp index 8444a9e..624e5d1 100644 --- a/manifests/maildir.pp +++ b/manifests/maildir.pp @@ -38,4 +38,5 @@ define backupninja::maildir( mode => 0600, require => File["${backupninja::client::configdir}"] } + package { rsync: ensure => installed } } -- cgit v1.2.3 From 4b24e2921731446d0f311176264efe41fa05f2b8 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Thu, 18 Jun 2009 12:11:41 -0400 Subject: add -o flag to treat only one backup, add rsync.log detection --- files/checkbackups.pl | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index 2084e86..c621109 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -42,10 +42,11 @@ our $opt_d = "/backup"; our $opt_c = 48 * 60 * 60; our $opt_w = 24 * 60 * 60; our $opt_v = 0; +our $opt_o; -if (!getopts('d:c:w:v')) { +if (!getopts('d:c:w:vo')) { print < ] [ -c ] [ -w ] -v +Usage: $0 [ -d ] [ -c ] [ -w ] [ -o ] [ -v ] EOF ; exit(); @@ -55,25 +56,35 @@ my $backupdir= $opt_d; my $crit = $opt_c; my $warn = $opt_w; -# XXX: this should be a complete backup registry instead -my @hosts=qx{ls $backupdir}; +my @hosts; +if (defined($opt_o)) { + @hosts=qx{hostname -f}; +} else { + # XXX: this should be a complete backup registry instead + @hosts=qx{ls $backupdir}; +} chdir($backupdir); my ($state, $message, @vservers, $host); foreach $host (@hosts) { chomp($host); + if ($opt_o) { + $dir = $backupdir; + } else { + $dir = $host; + } my $flag=""; my $type="unknown"; my $extra_msg=""; @vservers = (); $state = $STATE_UNKNOWN; $message = "???"; - if (-d $host) { + if (-d $dir) { # guess the backup type and find a proper stamp file to compare # XXX: the backup type should be part of the machine registry my $last_bak; - if (-d "$host/rdiff-backup") { - $flag="$host/rdiff-backup/rdiff-backup-data/backup.log"; + if (-d "$dir/rdiff-backup") { + $flag="$dir/rdiff-backup/rdiff-backup-data/backup.log"; $type="rdiff"; if (open(FLAG, $flag)) { while () { @@ -92,21 +103,21 @@ foreach $host (@hosts) { } close(FLAG); foreach my $vserver_dir (@vserver_dirs) { - $dir = "$host/rdiff-backup$vserver_dir"; + $dir = "$dir/rdiff-backup$vserver_dir"; if (opendir(DIR, $dir)) { @vservers = grep { /^[^\.]/ && -d "$dir/$_" } readdir(DIR); closedir DIR; } } - } elsif (-d "$host/dump") { + } elsif (-d "$dir/dump") { # XXX: this doesn't check backup consistency - $flag="$host/dump/" . `ls -tr $host/dump | tail -1`; + $flag="$dir/dump/" . `ls -tr $dir/dump | tail -1`; chomp($flag); $type="dump"; - } elsif (-d "$host/dup") { + } elsif (-r "$dir/rsync.log") { # XXX: this doesn't check backup consistency - $flag="$host/dup"; - $type="duplicity"; + $flag="$dir/rsync.log"; + $type="rsync"; } else { $message = "unknown system"; next; -- cgit v1.2.3 From 9df16ed173e45462f6b0a55d0267b31d5a3021f9 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Thu, 25 Jun 2009 11:45:54 -0400 Subject: detect properly duplicity backups --- files/checkbackups.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index c621109..be6bf70 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -114,6 +114,11 @@ foreach $host (@hosts) { $flag="$dir/dump/" . `ls -tr $dir/dump | tail -1`; chomp($flag); $type="dump"; + } elsif (-d "$dir/dup") { + # XXX: this doesn't check backup consistency + $flag="$dir/dup/" . `ls -tr $dir/dup | tail -1`; + chomp($flag); + $type="dup"; } elsif (-r "$dir/rsync.log") { # XXX: this doesn't check backup consistency $flag="$dir/rsync.log"; -- cgit v1.2.3 From de010623a8594900b9661db9c0dc8707a1e402fe Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Thu, 24 Sep 2009 11:16:05 -0400 Subject: fix vserver lookup script --- files/checkbackups.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/files/checkbackups.pl b/files/checkbackups.pl index be6bf70..80fc07f 100755 --- a/files/checkbackups.pl +++ b/files/checkbackups.pl @@ -103,10 +103,13 @@ foreach $host (@hosts) { } close(FLAG); foreach my $vserver_dir (@vserver_dirs) { - $dir = "$dir/rdiff-backup$vserver_dir"; - if (opendir(DIR, $dir)) { - @vservers = grep { /^[^\.]/ && -d "$dir/$_" } readdir(DIR); + $vsdir = "$dir/rdiff-backup$vserver_dir"; + if (opendir(DIR, $vsdir)) { + @vservers = grep { /^[^\.]/ && -d "$vsdir/$_" } readdir(DIR); + $opt_v && print STDERR "found vservers $vsdir: @vservers\n"; closedir DIR; + } else { + $opt_v && print STDERR "no vserver in $vsdir\n"; } } } elsif (-d "$dir/dump") { -- cgit v1.2.3 From 409c13a31f57ea6fff1bbfb669741c2128111d2e Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 20 Oct 2009 19:28:26 -0400 Subject: fix directory --- manifests/rdiff.pp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index 1d171b2..bcaee51 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -32,7 +32,6 @@ define backupninja::rdiff( default => $backuptag } - $directory = "$home/rdiff-backup/" include backupninja::client::defaults case $type { @@ -40,13 +39,14 @@ define backupninja::rdiff( case $host { false: { err("need to define a host for remote backups!") } } $real_home = $home ? { - false => $directory, + false => "/home/${user}-${name}", default => $home, } + $directory = "$real_home/rdiff-backup/" backupninja::server::sandbox { - "${user}-${name}": user => $user, host => $fqdn, dir => $home, + "${user}-${name}": user => $user, host => $fqdn, dir => $real_home, manage_ssh_dir => $ssh_dir_manage, ssh_dir => $ssh_dir, key => $key, authorized_keys_file => $authorized_keys_file, installuser => $installuser, backuptag => $real_backuptag, keytype => $backupkeytype, backupkeys => $backupkeystore, -- cgit v1.2.3 From aeae9f516faae6c1f0b68ce849eb6036716bcb01 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 20 Oct 2009 20:00:46 -0400 Subject: fix typo that yields to a weird error Could not create backup-nagios: Parameter type failed: interning empty string --- manifests/server.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/server.pp b/manifests/server.pp index 52cb11c..9db950a 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -120,7 +120,7 @@ class backupninja::server { } default: { @@ssh_authorized_key{ $real_user: - type => $key_type, + type => $keytype, key => $key, user => $real_user, target => "${real_ssh_dir}/${real_authorized_keys_file}", -- cgit v1.2.3 From 222ebf64d1f0f54120c510ce408a946bb08ce791 Mon Sep 17 00:00:00 2001 From: Antoine Beaupre Date: Tue, 20 Oct 2009 20:05:31 -0400 Subject: move the tag where it belongs (in remote) --- manifests/rdiff.pp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index bcaee51..c9363be 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -27,17 +27,16 @@ define backupninja::rdiff( $ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, $key = false, $backuptag = false, $home = false, $backupkeytype = "rsa", $backupkeystore = false, $extras = false) { - $real_backuptag = $backuptag ? { - false => "backupninja-$host", - default => $backuptag - } - include backupninja::client::defaults case $type { 'remote': { case $host { false: { err("need to define a host for remote backups!") } } - + $real_backuptag = $backuptag ? { + false => "backupninja-$host", + default => $backuptag + } + $real_home = $home ? { false => "/home/${user}-${name}", default => $home, -- cgit v1.2.3 From b380f1de1fe62d34f0788fedfb53c1354b0a31a3 Mon Sep 17 00:00:00 2001 From: anarcat Date: Mon, 7 Dec 2009 12:08:15 -0500 Subject: use the client classes for dependencies instead of directly defining packages --- manifests/maildir.pp | 3 +-- manifests/rdiff.pp | 11 +---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/manifests/maildir.pp b/manifests/maildir.pp index 1427af1..ab7ff55 100644 --- a/manifests/maildir.pp +++ b/manifests/maildir.pp @@ -22,7 +22,7 @@ define backupninja::maildir( $remove = false, $multiconnection = yes, $keepdaily='4', $keepweekly='2', $keepmonthly='2') { - include backupninja::client::defaults + include backupninja::client::maildir case $srcdir { false: { err("need to define a source directory to backup!") } } case $destdir { false: { err("need to define a destination directory to backup!") } } @@ -38,5 +38,4 @@ define backupninja::maildir( mode => 0600, require => File["${backupninja::client::defaults::configdir}"] } - package { rsync: ensure => installed } } diff --git a/manifests/rdiff.pp b/manifests/rdiff.pp index c9363be..2624ecd 100644 --- a/manifests/rdiff.pp +++ b/manifests/rdiff.pp @@ -27,7 +27,7 @@ define backupninja::rdiff( $ssh_dir = false, $authorized_keys_file = false, $installuser = true, $installkey = true, $key = false, $backuptag = false, $home = false, $backupkeytype = "rsa", $backupkeystore = false, $extras = false) { - include backupninja::client::defaults + include backupninja::client::rdiff-backup case $type { 'remote': { @@ -68,14 +68,5 @@ define backupninja::rdiff( mode => 0600, require => File["${backupninja::client::defaults::configdir}"] } - include backupninja::rdiff-installed -} - -class backupninja::rdiff-installed { - case $lsbdistcodename { - "etch": { $version = "1.2.5-1~bpo40+1" } - default: { $version = "installed" } - } - package { "rdiff-backup": ensure => $version } } -- cgit v1.2.3