From 54d77c688d6193da2d8f96f6e1937ecb13225d97 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Tue, 15 Mar 2011 21:13:11 -0400 Subject: Take advantage of nodata option in mysql backupninja config --- manifests/mysql.pp | 2 +- templates/mysql.conf.erb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/manifests/mysql.pp b/manifests/mysql.pp index 83d8f8f..f968cf9 100644 --- a/manifests/mysql.pp +++ b/manifests/mysql.pp @@ -18,7 +18,7 @@ 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 = true, - $vsname = false) + $vsname = false, $nodata = false) { $real_configfile = $configfile ? { diff --git a/templates/mysql.conf.erb b/templates/mysql.conf.erb index 14905fd..2efa4b1 100644 --- a/templates/mysql.conf.erb +++ b/templates/mysql.conf.erb @@ -16,3 +16,8 @@ compress = <%= compress ? 'yes' : 'no' %> <% if real_configfile %> configfile = <%= real_configfile %> <% end %> + +<% if nodata %> +nodata = <% nodata.each do |dbtable| -%><%= dbtable %> <% end -%> +<% end %> + -- cgit v1.2.3 From 1a06b02741983aef4c1b0342726f368a6f1de7db Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Tue, 15 Mar 2011 21:14:24 -0400 Subject: provide pgsql support --- manifests/init.pp | 1 + manifests/pgsql.pp | 29 +++++++++++++++++++++++++++++ templates/pgsql.conf.erb | 11 +++++++++++ 3 files changed, 41 insertions(+) create mode 100644 manifests/pgsql.pp create mode 100644 templates/pgsql.conf.erb diff --git a/manifests/init.pp b/manifests/init.pp index 23b4268..fba8cc4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,6 +4,7 @@ import "dup.pp" import "labelmount.pp" import "maildir.pp" import "mysql.pp" +import "pgsql.pp" import "rdiff.pp" import "server.pp" import "sh.pp" diff --git a/manifests/pgsql.pp b/manifests/pgsql.pp new file mode 100644 index 0000000..19fd46b --- /dev/null +++ b/manifests/pgsql.pp @@ -0,0 +1,29 @@ +# Safe PGSQL dumps, as part of a backupninja run. +# +# 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. +# +# 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). +# +# backupdir, compress, configfile: As defined in the +# backupninja documentation, with the caveat that hotcopy, sqldump, +# and compress take true/false rather than yes/no. +# +define backupninja::pgsql( + $order = 10, $ensure = present, $databases = 'all', $backupdir = "/var/backup/postgres", $compress = true, $vsname = false) +{ + + include backupninja::client::defaults + file { "${backupninja::client::defaults::configdir}/${order}_${name}.pgsql": + ensure => $ensure, + content => template('backupninja/pgsql.conf.erb'), + owner => root, + group => root, + mode => 0600, + require => File["${backupninja::client::defaults::configdir}"] + } +} diff --git a/templates/pgsql.conf.erb b/templates/pgsql.conf.erb new file mode 100644 index 0000000..7781ef4 --- /dev/null +++ b/templates/pgsql.conf.erb @@ -0,0 +1,11 @@ +<% if vsname %> +vsname = <%= vsname %> +<% end %> +<% if backupdir %> +backupdir = <%= backupdir %> +<% end %> +<% if databases %> +databases = <%= databases %> +<% end %> +compress = <%= compress ? 'yes' : 'no' %> + -- cgit v1.2.3 From 625ffd23ee88b26287fadd0db33d1ceababbac21 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Sat, 19 Mar 2011 23:55:22 -0400 Subject: We might get either a var or an array - we should be able to take either. --- templates/mysql.conf.erb | 8 +++++--- templates/pgsql.conf.erb | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/templates/mysql.conf.erb b/templates/mysql.conf.erb index 2efa4b1..c70aba0 100644 --- a/templates/mysql.conf.erb +++ b/templates/mysql.conf.erb @@ -17,7 +17,9 @@ compress = <%= compress ? 'yes' : 'no' %> configfile = <%= real_configfile %> <% end %> -<% if nodata %> -nodata = <% nodata.each do |dbtable| -%><%= dbtable %> <% end -%> -<% end %> +<% if nodata.is_a? String -%> +<%= 'nodata = ' + nodata %> +<% elsif nodata.is_a? Array -%> +<%= "nodata = " + nodata.map { |i| "#{i}" }.join(" ") %> +<% end -%> diff --git a/templates/pgsql.conf.erb b/templates/pgsql.conf.erb index 7781ef4..5ffa89c 100644 --- a/templates/pgsql.conf.erb +++ b/templates/pgsql.conf.erb @@ -4,8 +4,10 @@ vsname = <%= vsname %> <% if backupdir %> backupdir = <%= backupdir %> <% end %> -<% if databases %> -databases = <%= databases %> -<% end %> +<% if databases.is_a? String -%> +<%= 'databases = ' + databases %> +<% elsif databases.is_a? Array -%> +<%= "databases = " + databases.map { |i| "#{i}" }.join(" ") %> +<% end -%> compress = <%= compress ? 'yes' : 'no' %> -- cgit v1.2.3 From aaa21c19b69d381becc1d801d6664b71ba0db525 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Wed, 30 Mar 2011 10:41:39 -0400 Subject: Useful to control when a cron job runs to avoid all servers backing up at the same time. Also, specifying the backupninja command allows for wrapping it in other commands (e.g. to execute it from within a ssh-agent session so that authentication can happen via the monkeysphere). --- manifests/config.pp | 18 ++++++++++++++++++ templates/backupninja.cron.erb | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 templates/backupninja.cron.erb diff --git a/manifests/config.pp b/manifests/config.pp index 34e3a0e..89105b3 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -18,3 +18,21 @@ define backupninja::config( mode => 0644 } } + +# Write the backupninja cron job, allowing you to specify an alternate backupninja +# command (if you want to wrap it in any other commands, e.g. to allow it to use +# the monkeysphere for authentication), or a different schedule to run it on. +define backupninja::cron( + $backupninja_cmd = '/usr/sbin/backupninja', + $backupninja_test_cmd = $backupninja_cmd, + $cronfile = "/etc/cron.d/backupninja", + $min = "0", $hour = "*", $dom = "*", $month = "*", + $dow = "*") +{ + file { $cronfile: + content => template('backupninja/backupninja.cron.erb'), + owner => root, + group => root, + mode => 0644 + } +} diff --git a/templates/backupninja.cron.erb b/templates/backupninja.cron.erb new file mode 100644 index 0000000..ec392ca --- /dev/null +++ b/templates/backupninja.cron.erb @@ -0,0 +1,6 @@ +# /etc/cron.d/backupninja -- cron tab entry for package backupninja + +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +# # run backupninja +<%= min %> <%= hour %> <%= dom %> <%= month %> <%= dow %> root if [ -x <%= backupninja_test_cmd %> ]; then <%= backupninja_cmd %>; fi -- cgit v1.2.3