2015-12-19 10:16:05 +00:00
|
|
|
# == Class: rsnapshot::config
|
|
|
|
#
|
|
|
|
# manage host configs
|
|
|
|
class rsnapshot::config (
|
2015-12-19 21:49:34 +00:00
|
|
|
$hosts = $rsnapshot::hosts,
|
2015-12-21 12:33:29 +00:00
|
|
|
$cron_dir = $rsnapshot::cron_dir,
|
2015-12-19 10:16:05 +00:00
|
|
|
) {
|
2016-01-20 09:27:29 +00:00
|
|
|
|
2015-12-19 10:16:05 +00:00
|
|
|
# these are global settings, no point in setting them per host
|
|
|
|
$config_version = $rsnapshot::params::config_version
|
2016-01-18 18:54:53 +00:00
|
|
|
$lockpath = pick($rsnapshot::lockpath, $rsnapshot::params::config_lockpath, '/var/run/rsnapshot')
|
|
|
|
$conf_d = pick($rsnapshot::conf_d, $rsnapshot::params::conf_d, '/etc/rsnapshot')
|
2016-01-19 16:23:40 +00:00
|
|
|
$snapshot_root = pick($hosts['snapshot_root'], $rsnapshot::snapshot_root, '/backup')
|
2016-01-21 15:11:56 +00:00
|
|
|
$logpath = pick($rsnapshot::logpath, $rsnapshot::params::config_logpath)
|
2015-12-19 10:16:05 +00:00
|
|
|
# make sure lock path and conf path exist
|
|
|
|
file { $conf_d:
|
|
|
|
ensure => 'directory',
|
|
|
|
}
|
|
|
|
file { $lockpath:
|
|
|
|
ensure => 'directory',
|
|
|
|
}
|
2015-12-21 12:33:29 +00:00
|
|
|
file { $cron_dir:
|
|
|
|
ensure => 'directory',
|
|
|
|
}
|
2015-12-21 13:50:17 +00:00
|
|
|
file { $snapshot_root:
|
|
|
|
ensure => 'directory',
|
|
|
|
}
|
2016-01-21 15:11:56 +00:00
|
|
|
file { $logpath:
|
|
|
|
ensure => directory,
|
|
|
|
}
|
2016-01-22 08:12:32 +00:00
|
|
|
|
2015-12-19 20:39:36 +00:00
|
|
|
# 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
|
2017-02-27 10:58:18 +00:00
|
|
|
# the function checks $hosts for elements like:
|
2015-12-19 20:39:36 +00:00
|
|
|
# { foo => } and converts those to { foo => {} }
|
2015-12-19 20:13:55 +00:00
|
|
|
$hosts_clean = assert_empty_hash($hosts)
|
|
|
|
|
2016-01-19 15:01:54 +00:00
|
|
|
$hosts_clean.each |String $host, $hash | {
|
2016-01-22 14:44:12 +00:00
|
|
|
$backup_user = pick($hash['backup_user'], $rsnapshot::backup_user, $rsnapshot::params::config_backup_user, 'root')
|
2015-12-19 21:49:34 +00:00
|
|
|
$default_backup_dirs = pick($rsnapshot::default_backup, $rsnapshot::params::config_default_backup)
|
2016-01-20 09:27:29 +00:00
|
|
|
$backup_levels = pick($hash['backup_levels'], $rsnapshot::backup_levels, 'weekly')
|
2015-12-19 21:49:34 +00:00
|
|
|
$backup = $hash['backup']
|
2015-12-19 17:32:24 +00:00
|
|
|
$backup_defaults = pick($hash['backup_defaults'], $rsnapshot::params::config_backup_defaults)
|
2015-12-19 10:16:05 +00:00
|
|
|
$cmd_cp = pick($hash['cmd_cp'], $rsnapshot::params::config_cmd_cp)
|
|
|
|
$cmd_rm = pick($hash['cmd_rm'], $rsnapshot::params::config_cmd_rm)
|
|
|
|
$cmd_rsync = pick($hash['cmd_rsync'], $rsnapshot::params::config_cmd_rsync)
|
|
|
|
$cmd_ssh = pick($hash['cmd_ssh'], $rsnapshot::params::config_cmd_ssh)
|
|
|
|
$cmd_logger = pick($hash['cmd_logger'], $rsnapshot::params::config_cmd_logger)
|
|
|
|
$cmd_du = pick($hash['cmd_du'], $rsnapshot::params::config_cmd_du)
|
|
|
|
$cmd_rsnapshot_diff = pick_undef($hash['cmd_rsnapshot_diff'], $rsnapshot::params::config_cmd_rsnapshot_diff)
|
|
|
|
$cmd_preexec = pick_undef($hash['cmd_preexec'], $rsnapshot::params::config_cmd_preexec)
|
|
|
|
$cmd_postexec = pick_undef($hash['cmd_postexec'], $rsnapshot::params::config_cmd_postexec)
|
|
|
|
$use_lvm = pick_undef($hash['use_lvm'], $rsnapshot::params::config_use_lvm)
|
|
|
|
$linux_lvm_cmd_lvcreate = pick_undef($hash['linux_lvm_cmd_lvcreate'], $rsnapshot::params::config_linux_lvm_cmd_lvcreate)
|
|
|
|
$linux_lvm_cmd_lvremove = pick_undef($hash['linux_lvm_cmd_lvremove'], $rsnapshot::params::config_linux_lvm_cmd_lvremove)
|
|
|
|
$linux_lvm_cmd_mount = pick_undef($hash['linux_lvm_cmd_mount'], $rsnapshot::params::config_linux_lvm_cmd_mount)
|
|
|
|
$linux_lvm_cmd_umount = pick_undef($hash['linux_lvm_cmd_umount'], $rsnapshot::params::config_linux_lvm_cmd_umount)
|
|
|
|
$linux_lvm_snapshotsize = pick_undef($hash['linux_lvm_snapshotsize'], $rsnapshot::params::config_linux_lvm_snapshotsize)
|
|
|
|
$linux_lvm_snapshotname = pick_undef($hash['linux_lvm_snapshotname'], $rsnapshot::params::config_linux_lvm_snapshotname)
|
|
|
|
$linux_lvm_vgpath = pick_undef($hash['linux_lvm_vgpath'], $rsnapshot::params::config_linux_lvm_vgpath)
|
|
|
|
$linux_lvm_mountpath = pick_undef($hash['linux_lvm_mountpath'], $rsnapshot::params::config_linux_lvm_mountpath)
|
|
|
|
$no_create_root = pick_undef($hash['no_create_root'], $rsnapshot::params::config_no_create_root)
|
|
|
|
$verbose = pick($hash['verbose'], $rsnapshot::params::config_verbose)
|
|
|
|
$loglevel = pick($hash['loglevel'], $rsnapshot::params::config_loglevel)
|
|
|
|
$stop_on_stale_lockfile = pick_undef($hash['stop_on_stale_lockfile'], $rsnapshot::params::config_stop_on_stale_lockfile)
|
|
|
|
$rsync_short_args = pick($hash['rsync_short_args'], $rsnapshot::params::config_rsync_short_args)
|
|
|
|
$rsync_long_args = pick_undef($hash['rsync_long_args'], $rsnapshot::params::config_rsync_long_args)
|
|
|
|
$ssh_args = pick_undef($hash['ssh_args'], $rsnapshot::params::config_ssh_args)
|
|
|
|
$du_args = pick_undef($hash['du_args'], $rsnapshot::params::config_du_args)
|
|
|
|
$one_fs = pick_undef($hash['one_fs'], $rsnapshot::params::config_one_fs)
|
|
|
|
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
|
|
|
|
$retain = pick_undef($hash['retain'], $rsnapshot::params::config_retain)
|
2016-01-20 10:41:59 +00:00
|
|
|
$include = pick($hash['include'], [])
|
|
|
|
$exclude = pick($hash['exclude'], [])
|
2016-01-20 09:27:29 +00:00
|
|
|
$include_file = pick($hash['include_file'], $rsnapshot::params::config_include_file, "${conf_d}/${host}.include")
|
2015-12-19 10:16:05 +00:00
|
|
|
$exclude_file = pick($hash['exclude_file'], $rsnapshot::params::config_exclude_file, "${conf_d}/${host}.exclude")
|
|
|
|
$link_dest = pick_undef($hash['link_dest'], $rsnapshot::params::config_link_dest)
|
|
|
|
$sync_first = pick_undef($hash['sync_first'], $rsnapshot::params::config_sync_first)
|
|
|
|
$use_lazy_deletes = pick_undef($hash['use_lazy_deletes'], $rsnapshot::params::config_use_lazy_deletes)
|
2015-12-19 20:39:36 +00:00
|
|
|
$rsync_numtries = pick_undef($hash['rsync_numtries'], $rsnapshot::params::config_rsync_numtries)
|
2016-01-19 15:01:54 +00:00
|
|
|
#$backup_scripts = pick_undef($hash['backup_scripts'], $rsnapshot::params::config_backup_scripts)
|
2015-12-19 10:16:05 +00:00
|
|
|
|
|
|
|
$snapshot_dir = "${config_snapshot_root}/${host}"
|
|
|
|
$config = "${conf_d}/${host}.rsnapshot.conf"
|
2015-12-19 20:39:36 +00:00
|
|
|
$lockfile = "${lockpath}/${host}.pid"
|
|
|
|
$logfile = "${logpath}/${host}.log"
|
2015-12-19 10:16:05 +00:00
|
|
|
|
2015-12-19 21:49:34 +00:00
|
|
|
# fail if $backup_defaults is set to false and no $host[backup] defined
|
2015-12-19 21:57:56 +00:00
|
|
|
if ! $backup_defaults and ! $backup {
|
|
|
|
fail("==> Configuration error: backup_defaults is ${backup_defaults} and backup definitions for this host don't exist <==")
|
2015-12-19 21:49:34 +00:00
|
|
|
}
|
|
|
|
|
2015-12-19 20:39:36 +00:00
|
|
|
# merge the backup hashes to one if backup_default is set (defaults to true)
|
|
|
|
if $backup_defaults {
|
2015-12-21 14:16:58 +00:00
|
|
|
$backups = merge($backup, $default_backup_dirs)
|
2015-12-19 20:39:36 +00:00
|
|
|
} else {
|
2015-12-21 14:16:58 +00:00
|
|
|
$backups = $backup
|
2015-12-19 20:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# one of both interval or retain must be present
|
|
|
|
if ! ( $interval and $retain ) {
|
|
|
|
$interval = pick($hash['interval'], $rsnapshot::params::config_interval)
|
|
|
|
}
|
|
|
|
# rsnapshot wants numeric values
|
2015-12-21 14:16:58 +00:00
|
|
|
if $link_dest {
|
|
|
|
$link_dest_num = bool2num($link_dest)
|
2015-12-19 20:39:36 +00:00
|
|
|
}
|
2015-12-21 14:16:58 +00:00
|
|
|
if $sync_first {
|
|
|
|
$sync_first_num = bool2num($sync_first)
|
2015-12-19 20:39:36 +00:00
|
|
|
}
|
2015-12-21 14:16:58 +00:00
|
|
|
if $use_lazy_deletes {
|
|
|
|
$use_lazy_deletes_num = bool2num($use_lazy_deletes)
|
2015-12-19 20:39:36 +00:00
|
|
|
}
|
|
|
|
|
2016-01-20 09:27:29 +00:00
|
|
|
$real_include = $rsnapshot::include + $include
|
2016-01-20 10:41:59 +00:00
|
|
|
unless empty($real_include) {
|
2016-01-20 09:38:27 +00:00
|
|
|
file { $include_file:
|
|
|
|
ensure => 'file',
|
|
|
|
content => template('rsnapshot/include.erb'),
|
|
|
|
}
|
2015-12-19 20:39:36 +00:00
|
|
|
}
|
2016-01-20 09:27:29 +00:00
|
|
|
|
2016-01-21 15:11:56 +00:00
|
|
|
$real_exclude = $rsnapshot::exclude + $exclude
|
2016-01-20 10:41:59 +00:00
|
|
|
unless empty($real_exclude) {
|
2015-12-22 15:26:06 +00:00
|
|
|
file { $exclude_file:
|
|
|
|
ensure => 'file',
|
|
|
|
content => template('rsnapshot/exclude.erb'),
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 09:27:29 +00:00
|
|
|
|
2016-01-19 16:23:40 +00:00
|
|
|
concat { $config:
|
|
|
|
}
|
|
|
|
concat::fragment { "${config} for ${host}":
|
|
|
|
target => $config,
|
2015-12-21 17:39:21 +00:00
|
|
|
content => template('rsnapshot/rsnapshot.erb'),
|
2015-12-19 10:16:05 +00:00
|
|
|
}
|
2016-01-19 15:01:54 +00:00
|
|
|
|
2017-02-27 10:58:18 +00:00
|
|
|
|
2016-01-19 15:01:54 +00:00
|
|
|
|
2016-01-22 12:17:03 +00:00
|
|
|
if has_key($hash, backup_scripts) {
|
|
|
|
$hash[backup_scripts].each |$script, $scriptconf| {
|
|
|
|
$real_script = deep_merge($rsnapshot::params::backup_scripts[$script], $rsnapshot::backup_scripts[$script], $hash[backup_scripts][$script])
|
|
|
|
$dbbackup_user = $real_script[dbbackup_user]
|
|
|
|
$dbbackup_password = $real_script[dbbackup_password]
|
|
|
|
$dumper = $real_script[dumper]
|
|
|
|
$dump_flags = $real_script[dump_flags]
|
|
|
|
$ignore_dbs = $real_script[ignore_dbs]
|
2016-01-22 14:01:32 +00:00
|
|
|
$compress = $real_script[compress]
|
|
|
|
$commands = $real_script[commands]
|
2016-01-19 15:01:54 +00:00
|
|
|
|
2016-01-19 16:23:40 +00:00
|
|
|
concat::fragment { "${host}_${script}_backup":
|
2016-01-22 12:17:03 +00:00
|
|
|
target => $config,
|
|
|
|
content => "backup_script ${conf_d}/${host}.${script}.sh ./${script}\n",
|
2016-01-19 16:23:40 +00:00
|
|
|
}
|
2016-01-19 15:01:54 +00:00
|
|
|
|
2016-01-19 16:23:40 +00:00
|
|
|
file { "${conf_d}/${host}.${script}.sh":
|
|
|
|
ensure => present,
|
|
|
|
content => template("rsnapshot/${script}.sh.erb"),
|
|
|
|
mode => '0755',
|
|
|
|
}
|
2017-02-27 10:58:18 +00:00
|
|
|
|
2016-01-19 16:23:40 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-19 15:01:54 +00:00
|
|
|
|
2017-02-27 10:58:18 +00:00
|
|
|
# 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,
|
|
|
|
}
|
|
|
|
|
2015-12-21 14:16:58 +00:00
|
|
|
concat { $cronfile:
|
2015-12-20 17:23:37 +00:00
|
|
|
}
|
2015-12-22 13:55:21 +00:00
|
|
|
# create cron files for each backup level
|
2016-01-22 08:08:12 +00:00
|
|
|
# merge possible cron definitions to one
|
|
|
|
$real_cron = deep_merge($rsnapshot::params::cron, $rsnapshot::cron, $hash[cron])
|
2016-01-22 13:07:06 +00:00
|
|
|
concat::fragment { "mailto for $host":
|
|
|
|
content => "#This file is managed by puppet\nMAILTO=${real_cron[mailto]}\n\n",
|
|
|
|
target => $cronfile,
|
|
|
|
order => 1,
|
|
|
|
}
|
2015-12-21 23:20:58 +00:00
|
|
|
|
2016-01-22 08:08:12 +00:00
|
|
|
$backup_levels.each |String $level| {
|
2016-01-22 13:07:06 +00:00
|
|
|
$mailto = $real_cron[mailto]
|
2016-01-22 08:08:12 +00:00
|
|
|
$minute = rand_from_array($real_cron[$level][minute], "${host}.${level}.minute")
|
|
|
|
$hour = rand_from_array($real_cron[$level][hour], "${host}.${level}.hour")
|
|
|
|
$monthday = rand_from_array($real_cron[$level][monthday], "${host}.${level}.monthday")
|
|
|
|
$month = rand_from_array($real_cron[$level][month], "${host}.${level}.month")
|
|
|
|
$weekday = rand_from_array($real_cron[$level][weekday], "${host}.${level}.weekday")
|
2015-12-22 13:55:21 +00:00
|
|
|
|
2015-12-20 17:23:37 +00:00
|
|
|
concat::fragment { "${host}.${level}":
|
2015-12-21 14:16:58 +00:00
|
|
|
target => $cronfile,
|
2015-12-20 17:23:37 +00:00
|
|
|
content => template('rsnapshot/cron.erb'),
|
2016-01-22 13:07:06 +00:00
|
|
|
order => 2,
|
2015-12-20 17:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-19 10:16:05 +00:00
|
|
|
}
|
|
|
|
}
|