mirror of
https://github.com/krislamo/puppet-rsnapshot
synced 2025-09-13 15:59:28 +00:00
random time feature with ranges (random between 1am and 5 am: 1..5)
This commit is contained in:
@@ -16,7 +16,6 @@ class rsnapshot::config (
|
||||
ensure => 'directory',
|
||||
}
|
||||
|
||||
#$foo = ['1', '2', '3', '20..21']
|
||||
# $foo='*/5'
|
||||
#$qax = rand_from_array($foo)
|
||||
#notice("QAX is $qax ")
|
||||
@@ -34,6 +33,7 @@ class rsnapshot::config (
|
||||
$snapshot_root = pick($hash['snapshot_root'], $rsnapshot::params::config_snapshot_root)
|
||||
$backup_user = pick($hash['backup_user'], $rsnapshot::params::config_backup_user)
|
||||
$default_backup_dirs = pick($rsnapshot::default_backup, $rsnapshot::params::config_default_backup)
|
||||
$backup_levels = pick($hash['backup_levels'], $rsnapshot::params::config_backup_levels, 'weekly')
|
||||
$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)
|
||||
@@ -114,6 +114,37 @@ class rsnapshot::config (
|
||||
file { $config:
|
||||
content => template('rsnapshot/rsnapshot.erb')
|
||||
}
|
||||
|
||||
|
||||
########################### CRON ####################################################
|
||||
#30 1 * * * /usr/bin/rsnapshot -c /etc/rsnapshot/cmweb1.rsnapshot.conf daily
|
||||
#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,
|
||||
}
|
||||
|
||||
$backup_levels.each |String $level| {
|
||||
# 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'], '*')
|
||||
|
||||
$minute = rand_from_array($c_min, "${host}.${level}")
|
||||
$hour = rand_from_array($c_hour, "${host}.${level}")
|
||||
$monthday = rand_from_array($c_monthday, "${host}.${level}")
|
||||
$month = rand_from_array($c_month, "${host}.${level}")
|
||||
$weekday = rand_from_array($c_weekday, "${host}.${level}")
|
||||
concat::fragment { "${host}.${level}":
|
||||
target => "${cronfile}",
|
||||
content => template('rsnapshot/cron.erb'),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
7
manifests/cron.pp
Normal file
7
manifests/cron.pp
Normal file
@@ -0,0 +1,7 @@
|
||||
# this class sets up cron
|
||||
# * todo
|
||||
# let the user specify a range of hours and randomize cron creation in this range use rand for #args and return arg[rand]
|
||||
|
||||
class rsnapshot::cron {
|
||||
|
||||
}
|
@@ -7,6 +7,7 @@ class rsnapshot::params {
|
||||
$config_backup_user = 'root'
|
||||
$package_name = 'rsnapshot'
|
||||
$package_ensure = 'present'
|
||||
$config_backup_levels = [ 'daily', 'weekly', ]
|
||||
$config_backup_defaults = true
|
||||
$config_version = '1.2'
|
||||
$config_cmd_cp = '/bin/cp'
|
||||
@@ -60,5 +61,11 @@ class rsnapshot::params {
|
||||
}
|
||||
$config_backup_scripts = {}
|
||||
|
||||
$cron = {
|
||||
'minute' => ['0..20'],
|
||||
'hour' => ['21..23','0..4','5'],
|
||||
'monthday' => '*',
|
||||
'month' => '*',
|
||||
'weekday' => '*',
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user