From 7625d1b36608ea02a1bb7fe8f9d186200e149b5b Mon Sep 17 00:00:00 2001 From: Steven Ford Date: Tue, 18 Oct 2016 11:15:12 -0400 Subject: [PATCH 1/5] Add a tar handler modeled after the rdiff handler --- manifests/client/tar.pp | 13 +++++++++ manifests/tar.pp | 61 +++++++++++++++++++++++++++++++++++++++++ templates/tar.conf.erb | 22 +++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 manifests/client/tar.pp create mode 100644 manifests/tar.pp create mode 100644 templates/tar.conf.erb diff --git a/manifests/client/tar.pp b/manifests/client/tar.pp new file mode 100644 index 0000000..73df5f5 --- /dev/null +++ b/manifests/client/tar.pp @@ -0,0 +1,13 @@ +# == Class: backupninja::client::tar +# +# Manage tar installation +class backupninja::client::tar inherits backupninja::client::defaults { + if !defined(Package['tar']) { + if $tar_ensure_version == '' { + $tar_ensure_version = 'installed' + } + package { 'tar': + ensure => $tar_ensure_version, + } + } +} diff --git a/manifests/tar.pp b/manifests/tar.pp new file mode 100644 index 0000000..f8b7ddc --- /dev/null +++ b/manifests/tar.pp @@ -0,0 +1,61 @@ +# Run tar 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). +# +# include, exclude, compress, dateformat: 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::tar ( + $order = 90, + $ensure = present, + $when = "everyday at 01:00", + $backupname = "${fqdn}", + $backupdir = '/var/backups', + $compress = "bzip", + $dateformat = "%Y.%m.%d-%H%M", + $exclude = [ + $backupdir, + '/home/*/.gnupg', + '/home/*/.local/share/Trash', + '/home/*/.Trash', + '/home/*/.thumbnails', + '/home/*/.beagle', + '/home/*/.aMule', + '/home/*/gtk-gnutella-downloads', + '/tmp', + '/proc', + '/dev', + '/sys', + '/net', + '/misc', + '/media', + '/srv', + '/selinux', + ], + $include = [ + '/etc', + '/home', + '/usr/local', + ], + +) { + include ::backupninja::client::tar + file { "${backupninja::client::defaults::configdir}/${order}_${name}.tar": + ensure => $ensure, + content => template('backupninja/tar.conf.erb'), + owner => root, + group => root, + mode => '0600', + require => File[$backupninja::client::defaults::configdir], + } +} \ No newline at end of file diff --git a/templates/tar.conf.erb b/templates/tar.conf.erb new file mode 100644 index 0000000..4e4b8e4 --- /dev/null +++ b/templates/tar.conf.erb @@ -0,0 +1,22 @@ +# 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. + +<%= 'when = ' + @when if @when %> +<%= 'backupdir = ' + @backupdir if @backupdir %> +<%= 'backupname = ' + @backupname if @backupname %> +<%= 'compress = ' + @compress if @compress %> +<% if @include.is_a? String -%> +<%= 'includes = ' + @include %> +<% elsif @include.is_a? Array -%> +<%= 'includes = ' + @include.map { |i| "#{i}" }.join(" ") %> +<% end -%> + +<% if @exclude.is_a? String -%> +<%= 'excludes = ' + @exclude %> +<% elsif @exclude.is_a? Array -%> +<%= 'excludes = ' + @exclude.map { |i| "#{i}" }.join(" ") %> +<% end -%> + +<%= 'DATEFORMAT = ' + @dateformat if $dateformat %> \ No newline at end of file From 2dbc1fc7040088895f75a93064d54972baffa5cf Mon Sep 17 00:00:00 2001 From: Steven Ford Date: Tue, 18 Oct 2016 17:10:23 -0400 Subject: [PATCH 2/5] Allow sqldumpoptions to be set using an array --- manifests/mysql.pp | 3 ++- templates/mysql.conf.erb | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/manifests/mysql.pp b/manifests/mysql.pp index e3793a5..1ffd822 100644 --- a/manifests/mysql.pp +++ b/manifests/mysql.pp @@ -10,7 +10,7 @@ # that we can find the correct file to remove). # # user, dbusername, dbpassword, dbhost, databases, backupdir, -# hotcopy, sqldump, compress, configfile: As defined in the +# hotcopy, sqldump, sqldumpoptions, compress, configfile: As defined in the # backupninja documentation, with the caveat that hotcopy, sqldump, # and compress take true/false rather than yes/no. # @@ -25,6 +25,7 @@ $backupdir = false, $hotcopy = false, $sqldump = false, + $sqldumpoptions = '', $compress = false, $configfile = true, $vsname = false, diff --git a/templates/mysql.conf.erb b/templates/mysql.conf.erb index 575d04e..b9c4761 100644 --- a/templates/mysql.conf.erb +++ b/templates/mysql.conf.erb @@ -28,5 +28,16 @@ configfile = <%= @real_configfile %> <% end -%> hotcopy = <%= @hotcopy ? 'yes' : 'no' %> -sqldump = <%= @sqldump ? 'yes' : 'no' %> + +<% if @sqldump -%> +sqldump = yes +<% if @sqldumpoptions.is_a? String -%> +<%= 'sqldumpoptions = ' + @sqldumpoptions %> +<% elsif @sqldumpoptions.is_a? Array -%> +<%= 'sqldumpoptions = ' + @sqldumpoptions.map { |i| "#{i}" }.join(" ") %> +<% end -%> +<% else -%> +sqldump = no +<% end -%> + compress = <%= @compress ? 'yes' : 'no' %> From e22384079fe951d509982237cc6b05a090749eba Mon Sep 17 00:00:00 2001 From: Steven Ford Date: Mon, 24 Oct 2016 09:32:12 -0400 Subject: [PATCH 3/5] Allow local backup using file URL --- manifests/duplicity.pp | 44 +++++++++++++++++++++++------------------- templates/dup.conf.erb | 5 +++++ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/manifests/duplicity.pp b/manifests/duplicity.pp index d832a39..264663c 100644 --- a/manifests/duplicity.pp +++ b/manifests/duplicity.pp @@ -75,7 +75,9 @@ ], $vsinclude = false, # [dest] + $local = false, $incremental = 'yes', + $increments = 30, $keep = false, $bandwidthlimit = false, $sshoptions = false, @@ -102,27 +104,29 @@ validate_string($destdir) validate_string($password) - # guarantees there's a configured backup space for this backup - backupninja::server::sandbox { "${user}-${name}": - user => $destuser, - host => $desthost, - dir => $destdir, - manage_ssh_dir => $ssh_dir_manage, - ssh_dir => $ssh_dir, - authorized_keys_file => $authorized_keys_file, - installuser => $installuser, - backuptag => $backuptag, - backupkeys => $backupkeystore, - keytype => $backupkeytype, - } + if not $local { + # guarantees there's a configured backup space for this backup + backupninja::server::sandbox { "${user}-${name}": + user => $destuser, + host => $desthost, + dir => $destdir, + manage_ssh_dir => $ssh_dir_manage, + ssh_dir => $ssh_dir, + authorized_keys_file => $authorized_keys_file, + installuser => $installuser, + backuptag => $backuptag, + backupkeys => $backupkeystore, + keytype => $backupkeytype, + } - # the client's ssh key - backupninja::client::key { "${destuser}-${name}": - user => $destuser, - host => $desthost, - installkey => $installkey, - keytype => $backupkeytype, - keystore => $backupkeystore, + # the client's ssh key + backupninja::client::key { "${destuser}-${name}": + user => $destuser, + host => $desthost, + installkey => $installkey, + keytype => $backupkeytype, + keystore => $backupkeystore, + } } # the backupninja rule for this duplicity backup diff --git a/templates/dup.conf.erb b/templates/dup.conf.erb index 676cfba..a9275d5 100644 --- a/templates/dup.conf.erb +++ b/templates/dup.conf.erb @@ -35,9 +35,14 @@ [dest] <%= 'incremental = ' + @incremental if @incremental %> +<%= 'increments = ' + @increments if @increments %> <%= 'keep = ' + @keep if @keep %> <%= 'bandwidthlimit = ' + @bandwidthlimit if @bandwidthlimit %> <%= 'sshoptions = ' + @sshoptions if @sshoptions %> +<% if @local -%> +<%= 'desturl = file://' + @destdir if @destdir %> +<% else -%> <%= 'destdir = ' + @destdir if @destdir %> <%= 'desthost = ' + @desthost if @desthost %> <%= 'destuser = ' + @destuser if @destuser %> +<% end -%> From 91b7ca8e1bd67e5ca7908eca4c9a35c7feedfe04 Mon Sep 17 00:00:00 2001 From: Steven Ford Date: Mon, 24 Oct 2016 10:19:05 -0400 Subject: [PATCH 4/5] Use "!" instead of "not" --- manifests/duplicity.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/duplicity.pp b/manifests/duplicity.pp index 264663c..11313f3 100644 --- a/manifests/duplicity.pp +++ b/manifests/duplicity.pp @@ -104,7 +104,7 @@ validate_string($destdir) validate_string($password) - if not $local { + if !$local { # guarantees there's a configured backup space for this backup backupninja::server::sandbox { "${user}-${name}": user => $destuser, From b9b947e0476c02c3f9487a79073e589d1f34d377 Mon Sep 17 00:00:00 2001 From: Steven Ford Date: Mon, 24 Oct 2016 10:22:26 -0400 Subject: [PATCH 5/5] Only validate strings if backup type is not local --- manifests/duplicity.pp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/duplicity.pp b/manifests/duplicity.pp index 11313f3..c989dce 100644 --- a/manifests/duplicity.pp +++ b/manifests/duplicity.pp @@ -100,11 +100,11 @@ # the client with configs for this machine include backupninja::client::defaults - validate_string($desthost) - validate_string($destdir) - validate_string($password) + if !$local { + validate_string($desthost) + validate_string($destdir) + validate_string($password) - if !$local { # guarantees there's a configured backup space for this backup backupninja::server::sandbox { "${user}-${name}": user => $destuser,