From 90ee92acb88d32e544b3118b8edd3a0f410a1264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 27 Feb 2017 11:58:18 +0100 Subject: [PATCH] fix crontabs with dots on debian & added rsnapshot_prefix var --- manifests/config.pp | 23 ++++++++++++++++++----- manifests/init.pp | 3 ++- manifests/params.pp | 3 ++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 702765f..0f9edaf 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -31,7 +31,7 @@ class rsnapshot::config ( # custom function, if only a hostname is given as a param, this is an empty hash # the next loop would break as puppet does not allow to reassign variables - # the function checks $hosts for elements like: + # the function checks $hosts for elements like: # { foo => } and converts those to { foo => {} } $hosts_clean = assert_empty_hash($hosts) @@ -135,7 +135,7 @@ class rsnapshot::config ( content => template('rsnapshot/rsnapshot.erb'), } - + if has_key($hash, backup_scripts) { $hash[backup_scripts].each |$script, $scriptconf| { @@ -158,11 +158,25 @@ class rsnapshot::config ( content => template("rsnapshot/${script}.sh.erb"), mode => '0755', } - + } } - $cronfile = "${cron_dir}/${host}" + # cron on Debian seems to ignore files that have dots in their name; replace + # them with underscores (issue #2) + if $::osfamily == 'Debian' { + $cron_name = regsubst("${host}", '\.', '_') + $cronfile = "${cron_dir}/${rsnapshot_prefix}${cron_name}" + } + else { + $cronfile = "${cron_dir}/${rsnapshot_prefix}${host}" + } + + # Make sure old cron files without rsnapshot_prefix are removed + file { "${cron_dir}/${host}": + ensure => absent, + } + concat { $cronfile: } # create cron files for each backup level @@ -190,4 +204,3 @@ class rsnapshot::config ( } } } - diff --git a/manifests/init.pp b/manifests/init.pp index 46bb154..3e7845a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -19,6 +19,8 @@ class rsnapshot ( $snapshot_root = $rsnapshot::params::config_snapshot_root, $backup_levels = $rsnapshot::params::config_backup_levels, $cron_service_name = $rsnapshot::params::cron_service_name, + $rsnapshot_prefix = $rsnapshot::params::config_rsnapshot_prefix, + ) inherits rsnapshot::params { $default_backup_scripts = $rsnapshot::params::backup_scripts + $backup_scripts @@ -32,4 +34,3 @@ class rsnapshot ( contain '::rsnapshot::service' } } - diff --git a/manifests/params.pp b/manifests/params.pp index 3cff43b..c5efa35 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -42,8 +42,9 @@ class rsnapshot::params { $config_verbose = '2' $config_loglevel = '4' $config_stop_on_stale_lockfile = undef # bool + $config_rsnapshot_prefix = 'rsnapshot_' $config_rsync_short_args = '-az' - $config_rsync_long_args = undef # defaults are --delete --numeric-ids --relative --delete-excluded + $config_rsync_long_args = undef # defaults are --delete --numeric-ids --relative --delete-excluded $config_ssh_args = undef $config_du_args = undef $config_one_fs = undef