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

fix cron overrides (critical)

This commit is contained in:
Norbert Varzariu 2015-12-22 00:20:58 +01:00
parent 729ca63fe5
commit 4f41f41579
4 changed files with 70 additions and 38 deletions

2
TODO
View File

@ -1 +1,3 @@
validate for puppet 3 => impossible, misses the .each function validate for puppet 3 => impossible, misses the .each function
Fix Documentation

View File

@ -4,6 +4,8 @@ This function checks an input struct for undefined hashes in key => hash and ass
EOS EOS
)do |args| )do |args|
fail "Must receive one argument." if args.empty? fail "Must receive one argument." if args.empty?
return args if args.is_a?(String)
return args if args.is_a?(Integer)
args.each do |arg| args.each do |arg|
h = Hash.new h = Hash.new
arg.each_pair do |host, hash| arg.each_pair do |host, hash|

View File

@ -117,21 +117,49 @@ class rsnapshot::config (
concat { $cronfile: concat { $cronfile:
} }
$backup_levels.each |String $level| { $backup_levels.each |String $level| {
if validate_hash($hash) {
# allow to globally override ranges, create random numbers for backup_levels daily, weekly, monthly # allow to globally override ranges, create random numbers for backup_levels daily, weekly, monthly
if has_key($host, 'cron'){ if has_key($hash,cron){
$c_min = pick($host['cron'][$level]['minute'], $rsnapshot::params::cron[$level]['minute'], '*') if has_key($hash[cron], $level) {
$c_hour = pick($host['cron'][$level]['hour'], $rsnapshot::params::cron[$level]['hour'], '*') $cron = $hash[cron][$level]
$c_monthday = pick($host['cron'][$level]['monthday'], $rsnapshot::params::cron[$level]['monthday'], '*') if has_key($cron, minute) {
$c_month = pick($host['cron'][$level]['month'], $rsnapshot::params::cron[$level]['month'], '*') $c_min = $cron[minute]
$c_weekday = pick($host['cron'][$level]['weekday'], $rsnapshot::params::cron[$level]['weekday'], '*') } else {
$c_min = $rsnapshot::params::cron[$level][minute]
}
if has_key($cron, hour) {
$c_hour = $cron[hour]
} else {
$c_hour = $rsnapshot::params::cron[$level][hour]
}
if has_key($cron, monthday) {
$c_monthday = $cron[monthday]
} else {
$c_monthday = $rsnapshot::params::cron[$level][monthday]
}
if has_key($cron, month) {
$c_month = $cron[month]
} else {
$c_month = $rsnapshot::params::cron[$level][month]
}
if has_key($cron, weekday) {
$c_weekday = $cron[weekday]
} else {
$c_weekday = $rsnapshot::params::cron[$level][weekday]
} }
} else { } else {
$c_min = $rsnapshot::params::cron[$level]['minute'] $c_min = $rsnapshot::params::cron[$level][minute]
$c_hour = $rsnapshot::params::cron[$level]['hour'] $c_hour = $rsnapshot::params::cron[$level][hour]
$c_monthday = $rsnapshot::params::cron[$level]['monthday'] $c_monthday = $rsnapshot::params::cron[$level][monthday]
$c_month = $rsnapshot::params::cron[$level]['month'] $c_month = $rsnapshot::params::cron[$level][month]
$c_weekday = $rsnapshot::params::cron[$level]['weekday'] $c_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}.minute") $minute = rand_from_array($c_min, "${host}.${level}.minute")
$hour = rand_from_array($c_hour, "${host}.${level}.hour") $hour = rand_from_array($c_hour, "${host}.${level}.hour")

View File

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