Skip to content

Commit a21e21a

Browse files
Merge pull request #233 from reidmv/backup-iterate
Only require primary host param for backup
2 parents f5cef7a + 6ee4d4c commit a21e21a

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

plans/backup.pp

+22-32
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
# This plan can backup data as outlined at insert doc
44
#
55
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,
167

178
# 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+
)
2626

2727
$timestamp = Timestamp.new().strftime('%F_%T')
2828
$backup_directory = "${output_directory}/pe-backup-${timestamp}"
29+
2930
# Create backup folder
30-
apply_prep($primary_host)
3131
apply($primary_host){
3232
file { $backup_directory :
3333
ensure => 'directory',
@@ -36,21 +36,11 @@
3636
mode => '0770'
3737
}
3838
}
39+
3940
# Create an array of the names of databases and whether they have to be backed up to use in a lambda later
4041
$database_to_backup = [ $backup_orchestrator, $backup_activity, $backup_rbac, $backup_puppetdb]
4142
$database_names = [ 'pe-orchestrator' , 'pe-activity' , 'pe-rbac' , 'pe-puppetdb' ]
4243

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-
5444
if $backup_classification {
5545
out::message('# Backing up classification')
5646
run_task('peadm::backup_classification', $primary_host,
@@ -77,8 +67,8 @@
7767
if $value {
7868
out::message("# Backing up database ${database_names[$index]}")
7969
# 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
8272
} else {
8373
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
8474
}

spec/plans/backup_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
let(:params) { { 'primary_host' => 'primary' } }
66

77
it 'runs with default params' do
8-
allow_apply_prep
98
allow_apply
9+
expect_task('peadm::get_peadm_config').always_return({ 'primary_postgresql_host' => 'postgres' })
1010
expect_out_message.with_params('# Backing up ca and ssl certificates')
1111
# The commands all have a timestamp in them and frankly its prooved to hard with bolt spec to work this out
1212
allow_any_command

0 commit comments

Comments
 (0)