Skip to content

Commit d5886c4

Browse files
committed
Fix managing backup class and resources
Prior to this commit, the ensure for the cron entries in the backup class were hard coded to 'present' and could not be removed once set. This commit adds a new parameter to manage the cron jobs based on if $manage_database_backups is set.
1 parent e58e05e commit d5886c4

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

manifests/backup.pp

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
String $daily_databases_path = "${pe_databases::install_dir}/default_daily_databases.txt",
3030
String $backup_logging_directory = '/var/log/puppetlabs/pe_databases_backup',
3131
Integer $retention_policy = 2,
32+
Boolean $disable_maintenance = true,
3233
) {
3334

3435
file { $backup_logging_directory :
@@ -62,6 +63,11 @@
6263
refreshonly => true,
6364
}
6465

66+
$cron_ensure = $disable_maintenance ? {
67+
false => 'present',
68+
default => 'absent',
69+
}
70+
6571
# Since the cron job titles below include the array ('databases') of database names,
6672
# the crontab for pe-postgres needs to be reset if the array of database names changes,
6773
# otherwise the change create a new cron job and unmanage the old cron job.
@@ -72,7 +78,7 @@
7278
$databases_to_backup = $database_backup_set['databases']
7379
$databases = join($databases_to_backup, ' ')
7480
cron { "puppet_enterprise_database_backup_${databases_to_backup}":
75-
ensure => present,
81+
ensure => $cron_ensure,
7682
command => "${backup_script_path} -l ${backup_logging_directory} -t ${backup_directory} -r ${retention_policy} ${databases}",
7783
user => 'pe-postgres',
7884
minute => $database_backup_set['schedule']['minute'],

manifests/init.pp

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# @summary Tuning, maintenance, and backups for PE PostgreSQL.
44

55
class pe_databases (
6-
Boolean $manage_database_backups = false,
6+
Variant[Boolean,Undef] $manage_database_backups = undef,
77
# Manage the inclusion of the pg_repack class
88
Boolean $manage_database_maintenance = true,
99
# Manage the state of the maintenance tasks, i.e. systemd services and timers
@@ -41,17 +41,18 @@
4141
# In PE XL, the Master and Replica run PostgreSQL for all databases *except* for pe-puppetdb.
4242
include pe_databases::postgresql_settings::table_settings
4343
}
44-
45-
if $manage_database_backups {
46-
include pe_databases::backup
47-
}
4844
}
4945
else {
5046
notify { 'pe_databases_version_warn':
5147
message => 'This module only supports PE 2019.0.2 and later',
5248
loglevel => warning,
5349
}
5450
}
51+
if defined('$manage_database_backups') {
52+
class { 'pe_databases::backup':
53+
disable_maintenance => ! $manage_database_backups,
54+
}
55+
}
5556
}
5657
else {
5758
notify { 'pe_databases_systemd_warn':

0 commit comments

Comments
 (0)