|
3 | 3 | # This plan can backup data as outlined at insert doc |
4 | 4 | # |
5 | 5 | plan peadm::backup ( |
6 | | - # Standard |
7 | | - Peadm::SingleTargetSpec $primary_host, |
8 | | - Optional[Peadm::SingleTargetSpec] $replica_host = undef, |
9 | | - |
10 | | - # Large |
11 | | - Optional[TargetSpec] $compiler_hosts = undef, |
12 | | - |
13 | | - # Extra Large |
14 | | - Optional[Peadm::SingleTargetSpec] $primary_postgresql_host = undef, |
15 | | - Optional[Peadm::SingleTargetSpec] $replica_postgresql_host = undef, |
| 6 | + Peadm::SingleTargetSpec $primary_host, |
16 | 7 |
|
17 | 8 | # Which data to backup |
18 | | - Boolean $backup_orchestrator = true, |
19 | | - Boolean $backup_rbac = true, |
20 | | - Boolean $backup_activity = true, |
21 | | - Boolean $backup_ca_ssl = true, |
22 | | - Boolean $backup_puppetdb = false, |
23 | | - Boolean $backup_classification = true, |
24 | | - String $output_directory = '/tmp', |
25 | | -){ |
| 9 | + Boolean $backup_orchestrator = true, |
| 10 | + Boolean $backup_rbac = true, |
| 11 | + Boolean $backup_activity = true, |
| 12 | + Boolean $backup_ca_ssl = true, |
| 13 | + Boolean $backup_puppetdb = false, |
| 14 | + Boolean $backup_classification = true, |
| 15 | + String $output_directory = '/tmp', |
| 16 | +) { |
| 17 | + peadm::assert_supported_bolt_version() |
| 18 | + $cluster = run_task('peadm::get_peadm_config', $primary_host).first |
| 19 | + $arch = peadm::assert_supported_architecture( |
| 20 | + $primary_host, |
| 21 | + $cluster['replica_host'], |
| 22 | + $cluster['primary_postgresql_host'], |
| 23 | + $cluster['replica_postgresql_host'], |
| 24 | + $cluster['compiler_hosts'], |
| 25 | + ) |
26 | 26 |
|
27 | 27 | $timestamp = Timestamp.new().strftime('%F_%T') |
28 | 28 | $backup_directory = "${output_directory}/pe-backup-${timestamp}" |
| 29 | + |
29 | 30 | # Create backup folder |
30 | | - apply_prep($primary_host) |
31 | 31 | apply($primary_host){ |
32 | 32 | file { $backup_directory : |
33 | 33 | ensure => 'directory', |
|
36 | 36 | mode => '0770' |
37 | 37 | } |
38 | 38 | } |
| 39 | + |
39 | 40 | # Create an array of the names of databases and whether they have to be backed up to use in a lambda later |
40 | 41 | $database_to_backup = [ $backup_orchestrator, $backup_activity, $backup_rbac, $backup_puppetdb] |
41 | 42 | $database_names = [ 'pe-orchestrator' , 'pe-activity' , 'pe-rbac' , 'pe-puppetdb' ] |
42 | 43 |
|
43 | | - peadm::assert_supported_bolt_version() |
44 | | - |
45 | | - # Ensure input valid for a supported architecture |
46 | | - $arch = peadm::assert_supported_architecture( |
47 | | - $primary_host, |
48 | | - $replica_host, |
49 | | - $primary_postgresql_host, |
50 | | - $replica_postgresql_host, |
51 | | - $compiler_hosts, |
52 | | - ) |
53 | | - |
54 | 44 | if $backup_classification { |
55 | 45 | out::message('# Backing up classification') |
56 | 46 | run_task('peadm::backup_classification', $primary_host, |
|
77 | 67 | if $value { |
78 | 68 | out::message("# Backing up database ${database_names[$index]}") |
79 | 69 | # If the primary postgresql host is set then pe-puppetdb needs to be remotely backed up to primary. |
80 | | - if $database_names[$index] == 'pe-puppetdb' and $primary_postgresql_host { |
81 | | - run_command("sudo -u pe-puppetdb /opt/puppetlabs/server/bin/pg_dump \"sslmode=verify-ca host=${primary_postgresql_host} sslcert=/etc/puppetlabs/puppetdb/ssl/${primary_host}.cert.pem sslkey=/etc/puppetlabs/puppetdb/ssl/${primary_host}.private_key.pem sslrootcert=/etc/puppetlabs/puppet/ssl/certs/ca.pem dbname=pe-puppetdb\" -f /tmp/puppetdb_$(date +%F_%T).bin" , $primary_host) # lint:ignore:140chars |
| 70 | + if $database_names[$index] == 'pe-puppetdb' and $cluster['primary_postgresql_host'] { |
| 71 | + run_command("sudo -u pe-puppetdb /opt/puppetlabs/server/bin/pg_dump \"sslmode=verify-ca host=${cluster['primary_postgresql_host']} sslcert=/etc/puppetlabs/puppetdb/ssl/${primary_host}.cert.pem sslkey=/etc/puppetlabs/puppetdb/ssl/${primary_host}.private_key.pem sslrootcert=/etc/puppetlabs/puppet/ssl/certs/ca.pem dbname=pe-puppetdb\" -f /tmp/puppetdb_$(date +%F_%T).bin" , $primary_host) # lint:ignore:140chars |
82 | 72 | } else { |
83 | 73 | run_command("sudo -u pe-postgres /opt/puppetlabs/server/bin/pg_dump -Fc \"${database_names[$index]}\" -f \"${backup_directory}/${database_names[$index]}_$(date +%F_%T).bin\"" , $primary_host) # lint:ignore:140chars |
84 | 74 | } |
|
0 commit comments