1
0
mirror of https://github.com/krislamo/puppet-rsnapshot synced 2024-09-20 01:10:35 +00:00

allow to override default cron time ranges

This commit is contained in:
Norbert Varzariu 2015-12-21 11:25:11 +01:00
parent a63e9e47da
commit cafb00e201
3 changed files with 56 additions and 22 deletions

View File

@ -16,12 +16,6 @@ class rsnapshot::config (
ensure => 'directory',
}
# $foo='*/5'
#$qax = rand_from_array($foo)
#notice("QAX is $qax ")
# 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
@ -121,20 +115,30 @@ class rsnapshot::config (
#15 1 * * 0 /usr/bin/rsnapshot -c /etc/rsnapshot/cmweb1.rsnapshot.conf weekly
# 00 1 1 * * /usr/bin/rsnapshot -c /etc/rsnapshot/cmweb1.rsnapshot.conf monthly
$cronfile = "/tmp/rsnapshot.d/cron/${host}"
$cron = pick_default($hash['cron'], $rsnapshot::params::cron, 'absent')
concat { "${cronfile}":
# replace => false,
}
# $cron = pick($hash['cron'], $rsnapshot::params::cron)
# notify { "cron is ${cron} ": }
$backup_levels.each |String $level| {
if validate_hash($hash) {
# allow to globally override ranges, create random numbers for backup_levels daily, weekly, monthly
$c_min = pick($cron['minute'], $rsnapshot::params::cron['minute'], '*')
$c_hour = pick($cron['hour'], $rsnapshot::params::cron['hour'], '*')
$c_monthday = pick($cron['monthday'], $rsnapshot::params::cron['monthday'], '*')
$c_month = pick($cron['month'], $rsnapshot::params::cron['month'], '*')
$c_weekday = pick($cron['weekday'], $rsnapshot::params::cron['weekday'], '*')
if has_key($host, 'cron'){
$c_min = pick($host['cron'][$level]['minute'], $rsnapshot::params::cron[$level]['minute'], '*')
$c_hour = pick($host['cron'][$level]['hour'], $rsnapshot::params::cron[$level]['hour'], '*')
$c_monthday = pick($host['cron'][$level]['monthday'], $rsnapshot::params::cron[$level]['monthday'], '*')
$c_month = pick($host['cron'][$level]['month'], $rsnapshot::params::cron[$level]['month'], '*')
$c_weekday = pick($host['cron'][$level]['weekday'], $rsnapshot::params::cron[$level]['weekday'], '*')
}
} else {
$c_min = $rsnapshot::params::cron[$level]['minute']
$c_hour = $rsnapshot::params::cron[$level]['hour']
$c_monthday = $rsnapshot::params::cron[$level]['monthday']
$c_month = $rsnapshot::params::cron[$level]['month']
$c_weekday = $rsnapshot::params::cron[$level]['weekday']
}
$minute = rand_from_array($c_min, "${host}.${level}")
$hour = rand_from_array($c_hour, "${host}.${level}")
$monthday = rand_from_array($c_monthday, "${host}.${level}")

View File

@ -61,11 +61,41 @@ class rsnapshot::params {
}
$config_backup_scripts = {}
# $cron = {
# 'minute' => '0..59',
# 'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
# 'monthday' => '0..28',
# 'month' => '1..12',
# 'weekday' => '0..6',
# }
$cron = {
'hourly' => {
'minute' => '0..59',
'hour' => '*', # you could also do: ['21..23','0..4','5'],
'monthday' => '*',
'month' => '*',
'weekday' => '*',
},
'daily' => {
'minute' => '0..59',
'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
'monthday' => '*',
'month' => '*',
'weekday' => '*',
},
'weekly' => {
'minute' => '0..59',
'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
'monthday' => '*',
'month' => '*',
'weekday' => '0..6',
},
'monthly' => {
'minute' => '0..59',
'hour' => '0..23', # you could also do: ['21..23','0..4','5'],
'monthday' => '0..28',
'month' => '1..12',
'weekday' => '0..6',
'month' => '*',
'weekday' => '*',
},
}
}

View File

@ -1 +1 @@
<%= @minute %> <%= @hour %> <%= @monthday %> <%= @weekday %> root /usr/bin/rsnapshot -c <%= @config %> <%= @level %>
<%= @minute %> <%= @hour %> <%= @month %> <%= @monthday %> <%= @weekday %> root /usr/bin/rsnapshot -c <%= @config %> <%= @level %>