diff --git a/manifests/config.pp b/manifests/config.pp index 9438812..2fcabb6 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -2,7 +2,7 @@ # # manage host configs class rsnapshot::config ( - $hosts = $rsnapshot::hosts, + $hosts = $rsnapshot::hosts, ) { # these are global settings, no point in setting them per host $config_version = $rsnapshot::params::config_version @@ -25,7 +25,8 @@ class rsnapshot::config ( $hosts_clean.each |String $host, Hash $hash | { $snapshot_root = pick($hash['snapshot_root'], $rsnapshot::params::config_snapshot_root) $backup_user = pick($hash['backup_user'], $rsnapshot::params::config_backup_user) - $backup = pick($hash['backup'], $rsnapshot::params::config_backup) + $default_backup_dirs = pick($rsnapshot::default_backup, $rsnapshot::params::config_default_backup) + $backup = $hash['backup'] $backup_defaults = pick($hash['backup_defaults'], $rsnapshot::params::config_backup_defaults) $cmd_cp = pick($hash['cmd_cp'], $rsnapshot::params::config_cmd_cp) $cmd_rm = pick($hash['cmd_rm'], $rsnapshot::params::config_cmd_rm) @@ -72,9 +73,14 @@ class rsnapshot::config ( $lockfile = "${lockpath}/${host}.pid" $logfile = "${logpath}/${host}.log" + # fail if $backup_defaults is set to false and no $host[backup] defined + if ! $backup_defaults and ! $backup { + fail("There is no point in not specifying a backup, I got backup_defaults: ${backup_defaults} and backup definitions for this host (${host}) don't exist") + } + # merge the backup hashes to one if backup_default is set (defaults to true) if $backup_defaults { - $backups = merge($backup, $rsnapshot::params::config_backup) + $backups = merge($backup, $default_backup_dirs) } else { $backups = $backup } diff --git a/manifests/init.pp b/manifests/init.pp index 4dd72a1..48dc1c3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -9,6 +9,7 @@ class rsnapshot ( $conf_d = $rsnapshot::params::conf_d, $logpath = $rsnapshot::params::config_logpath, $lockpath = $rsnapshot::params::config_lockpath, + $default_backup = $rsnapshot::params::config_default_backup, ) inherits rsnapshot::params { # anchor { 'rsnapshot::begin': } -> diff --git a/manifests/params.pp b/manifests/params.pp index 90f0ebc..72e5507 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -54,7 +54,7 @@ class rsnapshot::params { $config_sync_first = false $config_rsync_numtries = 1 $config_use_lazy_deletes = false - $config_backup = { + $config_default_backup = { '/etc' => './', '/home' => './', } diff --git a/templates/rsnapshot.erb b/templates/rsnapshot.erb index 0e59054..62ceadc 100644 --- a/templates/rsnapshot.erb +++ b/templates/rsnapshot.erb @@ -128,7 +128,9 @@ linux_lvm_mountpath <%= @linux_lvm_mountpath %> <% end -%> <% end -%> <% @backups.each_pair do |source, dest| -%> -<% if @backup_user != '' -%> +<% if @host == 'localhost' -%> +backup <%= source %> <%=dest%> +<% elsif @backup_user != '' -%> backup <%= @backup_user %>@<%=@host%>:<%= source %> <%=dest%> <% else -%> backup <%=@host%>:<%= source %> <%=dest%>