From 69f858c75573f8be2ab8b36ad5fb32b1a19e716c Mon Sep 17 00:00:00 2001 From: Elaine McCloskey <44435892+elainemccloskey@users.noreply.github.com> Date: Wed, 6 Jul 2022 11:57:08 +0100 Subject: [PATCH] Remove deprecated backup functionality --- README.md | 53 +---------- files/puppet_enterprise_database_backup.sh | 85 ------------------ .../backup_schedule_alt_example_1.yaml | 30 ------- .../backup_schedule_alt_example_2.yaml | 50 ----------- .../backup_schedule_default.yaml | 19 ---- manifests/backup.pp | 90 ------------------- manifests/init.pp | 12 +-- spec/acceptance/backup_spec.rb | 15 ---- spec/classes/backup_spec.rb | 13 --- spec/classes/init_spec.rb | 10 --- 10 files changed, 3 insertions(+), 374 deletions(-) delete mode 100755 files/puppet_enterprise_database_backup.sh delete mode 100644 hieradata_examples/backup_schedule_alt_example_1.yaml delete mode 100644 hieradata_examples/backup_schedule_alt_example_2.yaml delete mode 100644 hieradata_examples/backup_schedule_default.yaml delete mode 100644 manifests/backup.pp delete mode 100644 spec/acceptance/backup_spec.rb delete mode 100644 spec/classes/backup_spec.rb diff --git a/README.md b/README.md index 48beab7..2dac0f7 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,9 @@ Table of Contents - [What does this module provide?](#what-does-this-module-provide) - [Usage](#usage) - [Items you may want to configure](#items-you-may-want-to-configure) - - [Backup Schedule](#backup-schedule) - - [Backup Retention Policy](#backup-retention-policy) - [Disable Maintenance](#disable-maintenance) - [General PostgreSQL Recommendations](#general-postgresql-recommendations) - [Tuning](#tuning) - - [Backups](#backups) - [Maintenance](#maintenance) - [PostgreSQL Settings](#postgresql-settings) - [maintenance_work_mem](#maintenance_work_mem) @@ -23,7 +20,7 @@ Table of Contents # Overview -This module provides tuning, maintenance, and backups for PE PostgreSQL. +This module provides tuning, and maintenance for PE PostgreSQL. ## What does this module provide? @@ -31,9 +28,6 @@ This module provides the following functionaility 1. Customized settings for PE PostgreSQL 1. Maintenance to keep the `pe-puppetdb` database lean and fast -1. Backups for all PE PostgreSQL databases, disabled by default - - The `pe-puppetdb` database is backed up every week - - Other databases are backed up every night ## Usage @@ -46,34 +40,12 @@ It is not recommended to classify using a pre-existing node group in the PE Cons ## Items you may want to configure -### Backup Schedule -> WARNING: The backup functionality in this module has been deprecated and will be removed in a future release. +> WARNING: The backup functionality in this module has been removed. Please refer to the [PE Backup and Restore documentation](https://puppet.com/docs/pe/latest/backing_up_and_restoring_pe.html) for details on how to backup. You should ensure the parameter `pe_databases::manage_database_backups` and any parameters from the `pe_databases::backup` class are removed from classification or hiera. You should also clean up associated crontab entries. -Backups are not activated by default but can be enabled by setting the following parameter: - -Hiera classification example - -``` -pe_databases::manage_database_backups:: true -``` - -You can modify the default backup schedule by provide an array of hashes that describes the databases to backup and their backup schedule. -Please refer to the [hieradata_examples](https://github.com/puppetlabs/puppetlabs-pe_databases/tree/main/hieradata_examples) directory of this repository for examples. - -> IMPORTANT NOTE: If you change the default schedule, it will stop managing the associated crontab entries, and there's not a clean way to automatically remove unmanaged crontab entries. -So you should delete all pe-postgres crontab entries via `crontab -r -u pe-postgres` and let Puppet repopulate them if you change the default schedule. -Otherwise, you will create duplicate backups. - -### Backup Retention Policy - -By default, the backup script will retain two backups for each database. -When the backup script runs, it will remove the older of the two backups before starting the backup itself. -You can configure the retention policy by setting `pe_databases::backup::retention_policy: `. - ### Disable Maintenance The maintenance systemd timers will perform a `pg_repack` on various `pe-puppetdb` tables to keep them lean and fast. @@ -93,27 +65,6 @@ If you are using a dedicated node for PE PostgreSQL, then some of the settings c This module attempts to provide default settings that accommodate both a Monolithic install and a dedicated PE PostgreSQL instance. Those defaults change based on the `$all_in_one_pe` parameter. -## Backups - -> WARNING: The backup functionality in this module has been deprecated and will be removed in a future release. -Please refer to the [PE Backup and Restore documentation](https://puppet.com/docs/pe/latest/backing_up_and_restoring_pe.html) for details on how to backup. -You should ensure the parameter `pe_databases::manage_database_backups` and any parameters from the `pe_databases::backup` class are removed from classification or hiera. -You should also clean up associated crontab entries. - -This is the documentation for Pupet Enterprise backups: - -https://puppet.com/docs/pe/latest/backing_up_and_restoring_pe.html - -This module provides an alternative to backup just the PE PostgreSQL databases. - -It is recommended that you backup each database individually so that if you have an issue with one database you do not have to restore all databases. - -Under ideal conditions you would backup all databases daily, however, backing up large databases such as `pe-puppetdb`, results in excessive disk I/O so you may prefer to backup `pe-puppetdb` weekly while backing up the rest of the smaller databases daily. - -The choice to backup `pe-puppetdb` more frequently should be based on the business needs. - -This module provides a script for backing up PE PostgreSQL databases and two default cron jobs: one weekly to back up the `pe-puppetdb` database, and one daily to backup every database except `pe-puppetdb`. - ## Maintenance This module provides systemd timers to pg_repack tables in the `pe-puppetdb` database: diff --git a/files/puppet_enterprise_database_backup.sh b/files/puppet_enterprise_database_backup.sh deleted file mode 100755 index 1c86c0d..0000000 --- a/files/puppet_enterprise_database_backup.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash - -usage() { - echo "usage: $0 [-t TARGET_BACKUP_DIRECTORY] [-l LOG_DIRECTORY] [-r RETENTION] [DATABASE_N ...]" - exit 1 -} - -while [[ $1 ]]; do - case "$1" in - -t) - backup_dir="$2" - shift 2 - ;; - -l) - log_dir="$2" - shift 2 - ;; - -r) - retention="$2" - shift 2 - ;; - # If given the end of options string, shift it out and break - --) - shift - break - ;; - # No need to shift if we've processed all options - *) - break - ;; - esac -done - -# The remaining parameters will be the databases to backup -databases=("$@") -# shellcheck disable=SC2128 -# We only care if the array contains any elements -[[ $databases ]] || usage - -[[ $pg_version ]] || pg_version="$(/usr/local/bin/facter -p pe_postgresql_info.installed_server_version)" -backup_dir="${backup_dir:-/opt/puppetlabs/server/data/postgresql/$pg_version/backups}" -log_dir="${log_dir:-/var/log/puppetlabs/pe_databases_backup}" -retention="${retention:-2}" - -for db in "${databases[@]}"; do - # For each db, redirect all output to the log inside the backup dir - exec &>"${log_dir}/${db}.log" - echo "Enforcing retention policy of storing only $retention backups for $db" - - unset backups - # Starting inside <(), use stat to print mtime and the filename and pipe to sort - # Add the filename to the backups array, giving us a sorted list of filenames - while IFS= read -r -d '' line; do - backups+=("${line#* }") - done < <(stat --printf '%Y %n\0' "${backup_dir}/${db}_"* 2>/dev/null | sort -nz) - - # Our array offset will be the number of backups - $retention + 1 - # e.g. if we have 2 existing backups and retention=2, offset will be one - # We'll delete from element 0 to 1 of the array, leaving one backup. - # The subsequent backup will leave us with 2 again - offset=$(( ${#backups[@]} - retention + 1 )) - - if (( offset > 0 )); then - # Continue if we're retaining more copies of the db than currently exist - # This will also be true if no backups currently exist - rm -f -- "${backups[@]:0:$offset}" - fi - - echo "Starting dump of database: $db" - - if [[ $db == 'pe-classifier' ]]; then - # Save space before backing up by clearing unused node_check_ins table. - /opt/puppetlabs/server/bin/psql -d pe-classifier -c 'TRUNCATE TABLE node_check_ins' || \ - echo "Failed to truncate node_check_ins table" - fi - - datetime="$(date +%Y%m%d%S)" - - /opt/puppetlabs/server/bin/pg_dump -Fc "$db" -f "${backup_dir}/${db}_$datetime.bin" || { - echo "Failed to dump database $db" - exit 1 - } - - echo "Completed dump of database: ${db}" -done diff --git a/hieradata_examples/backup_schedule_alt_example_1.yaml b/hieradata_examples/backup_schedule_alt_example_1.yaml deleted file mode 100644 index f604f55..0000000 --- a/hieradata_examples/backup_schedule_alt_example_1.yaml +++ /dev/null @@ -1,30 +0,0 @@ -pe_databases::backup::databases_and_backup_schedule: - - - 'databases': - - 'pe-classifier' - - 'pe-orchestrator' - - 'pe-rbac' - 'schedule': - 'minute': '30' - 'hour': '22' - - - 'databases': - - 'pe-activity' - 'schedule': - 'minute': '0' - 'hour': '1' - 'weekday': '6' - - - 'databases': - - 'pe-postgres' - 'schedule': - 'minute': '0' - 'hour': '2' - 'weekday': '6' - - - 'databases': - - 'pe-puppetdb' - 'schedule': - 'minute': '0' - 'hour': '2' - 'weekday': '7' diff --git a/hieradata_examples/backup_schedule_alt_example_2.yaml b/hieradata_examples/backup_schedule_alt_example_2.yaml deleted file mode 100644 index c9755c4..0000000 --- a/hieradata_examples/backup_schedule_alt_example_2.yaml +++ /dev/null @@ -1,50 +0,0 @@ -pe_databases::backup::databases_and_backup_schedule: - - - 'databases': - - 'pe-activity' - 'schedule': - 'minute': '0' - 'hour': '1' - 'weekday': '6' - - - 'databases': - - 'pe-classifier' - 'schedule': - 'minute': '0' - 'hour': '2' - 'weekday': '6' - - - 'databases': - - 'pe-inventory' - 'schedule': - 'minute': '0' - 'hour': '3' - 'weekday': '6' - - - 'databases': - - 'pe-orchestrator' - 'schedule': - 'minute': '0' - 'hour': '4' - 'weekday': '6' - - - 'databases': - - 'pe-postgres' - 'schedule': - 'minute': '0' - 'hour': '5' - 'weekday': '6' - - - 'databases': - - 'pe-rbac' - 'schedule': - 'minute': '0' - 'hour': '6' - 'weekday': '6' - - - 'databases': - - 'pe-puppetdb' - 'schedule': - 'minute': '0' - 'hour': '2' - 'weekday': '7' diff --git a/hieradata_examples/backup_schedule_default.yaml b/hieradata_examples/backup_schedule_default.yaml deleted file mode 100644 index 79a698a..0000000 --- a/hieradata_examples/backup_schedule_default.yaml +++ /dev/null @@ -1,19 +0,0 @@ -pe_databases::backup::databases_and_backup_schedule: - - - 'databases': - - 'pe-activity' - - 'pe-classifier' - - 'pe-inventory' - - 'pe-orchestrator' - - 'pe-postgres' - - 'pe-rbac' - 'schedule': - 'minute': '30' - 'hour': '22' - - - 'databases': - - 'pe-puppetdb' - 'schedule': - 'minute': '0' - 'hour': '2' - 'weekday': '7' diff --git a/manifests/backup.pp b/manifests/backup.pp deleted file mode 100644 index fbd03a4..0000000 --- a/manifests/backup.pp +++ /dev/null @@ -1,90 +0,0 @@ -# Backup PostgreSQL -# -# @summary Backup PostgreSQL - -class pe_databases::backup ( - Array[Hash] $databases_and_backup_schedule = - [ - { - 'databases' => pe_databases::version_based_databases(), - 'schedule' => - { - 'minute' => '30', - 'hour' => '22', - }, - }, - { - 'databases' => ['pe-puppetdb'], - 'schedule' => - { - 'minute' => '0', - 'hour' => '2', - 'weekday' => '7', - }, - } - ], - String $psql_version = $pe_databases::psql_version, - String $backup_directory = "/opt/puppetlabs/server/data/postgresql/${psql_version}/backups", - String $backup_script_path = "${pe_databases::scripts_dir}/puppet_enterprise_database_backup.sh", - String $daily_databases_path = "${pe_databases::install_dir}/default_daily_databases.txt", - String $backup_logging_directory = '/var/log/puppetlabs/pe_databases_backup', - Integer $retention_policy = 2, - Boolean $disable_maintenance = true, -) { - - file { $backup_logging_directory : - ensure => 'directory', - owner => 'pe-postgres', - group => 'pe-postgres', - } - - file { 'pe_databases_backup_script' : - ensure => file, - owner => 'pe-postgres', - group => 'pe-postgres', - mode => '0750', - path => $backup_script_path, - source => 'puppet:///modules/pe_databases/puppet_enterprise_database_backup.sh', - } - - # Track the (databases backed up by default every day). - file { 'pe_databases_default_daily_databases' : - ensure => 'file', - path => $daily_databases_path, - content => "${pe_databases::version_based_databases()}", - notify => Exec['reset_pe-postgres_crontab'], - } - - # Reset the crontab for pe-postgres if the (databases backed up by default every day) change. - exec { 'reset_pe-postgres_crontab': - path => '/usr/local/bin/:/bin/:/usr/bin', - command => 'crontab -r -u pe-postgres', - onlyif => 'crontab -l -u pe-postgres', - refreshonly => true, - } - - $cron_ensure = $disable_maintenance ? { - false => 'present', - default => 'absent', - } - - # Since the cron job titles below include the array ('databases') of database names, - # the crontab for pe-postgres needs to be reset if the array of database names changes, - # otherwise the change create a new cron job and unmanage the old cron job. - - # TODO: This takes two runs to become idempotent. Why? - - $databases_and_backup_schedule.each | Hash $database_backup_set | { - $databases_to_backup = $database_backup_set['databases'] - $databases = join($databases_to_backup, ' ') - cron { "puppet_enterprise_database_backup_${databases_to_backup}": - ensure => $cron_ensure, - command => "${backup_script_path} -l ${backup_logging_directory} -t ${backup_directory} -r ${retention_policy} ${databases}", - user => 'pe-postgres', - minute => $database_backup_set['schedule']['minute'], - hour => $database_backup_set['schedule']['hour'], - weekday => $database_backup_set['schedule']['weekday'], - require => [File['pe_databases_backup_script'], File['pe_databases_default_daily_databases']], - } - } -} diff --git a/manifests/init.pp b/manifests/init.pp index d14931e..d83c332 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -43,17 +43,7 @@ include pe_databases::postgresql_settings::table_settings } } - # Because this parameter is a value of undef with a data type of Undef, - # We can the NotUndef type to determine if the value has been set - if $manage_database_backups =~ NotUndef { - class { 'pe_databases::backup': - disable_maintenance => ! $manage_database_backups, - } - notify { 'pe_databases_backup_deprecate_warn': - message => 'The backup functionality in the pe_databases module has been deprecated and will be removed in a future release', - loglevel => warning, - } - } + } else { notify { 'pe_databases_version_warn': diff --git a/spec/acceptance/backup_spec.rb b/spec/acceptance/backup_spec.rb deleted file mode 100644 index 7b1db53..0000000 --- a/spec/acceptance/backup_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'pe_databases with manage database backups' do - it 'applies the class with default parameters' do - pp = <<-MANIFEST - class { 'pe_databases': - manage_database_backups => true - }#{' '} - MANIFEST - - # Expect a change due to backup notify - apply_manifest(pp) - apply_manifest(pp, expect_changes: true) - end -end diff --git a/spec/classes/backup_spec.rb b/spec/classes/backup_spec.rb deleted file mode 100644 index c43c969..0000000 --- a/spec/classes/backup_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' - -describe 'pe_databases::backup' do - context 'when backing up tables' do - let(:pre_condition) { 'include pe_databases' } - - it { - # I have no idea how this works, but these are the resources we should end up with - is_expected.to contain_cron('puppet_enterprise_database_backup_[pe-activity, pe-classifier, pe-inventory, pe-orchestrator, pe-postgres, pe-rbac]') - is_expected.to contain_cron('puppet_enterprise_database_backup_[pe-puppetdb]') - } - end -end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index a8308cf..debdb87 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -24,14 +24,4 @@ it { is_expected.to contain_notify('pe_databases_systemd_warn') } end - - context 'backups are not included by default' do - it { is_expected.not_to contain_class('pe_databases::backup') } - end - - context 'backups are included if configured' do - let(:params) { { manage_database_backups: true } } - - it { is_expected.to contain_class('pe_databases::backup') } - end end