Skip to content

Commit c5bb51e

Browse files
committed
Add puppetdb export/import step to restore
This should help keep current cluster PuppetDB knowledge of cluster hosts after restoring PuppetDB data from a backup
1 parent 74d3a99 commit c5bb51e

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

plans/restore.pp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@
9595
| CMD
9696
}
9797

98+
# Use PuppetDB's /pdb/admin/v1/archive API to SAVE data currently in PuppetDB.
99+
# Otherwise we'll completely lose it if/when we restore.
100+
# TODO: consider adding a heuristic to skip when innappropriate due to size
101+
# or other factors.
102+
if getvar('recovery_opts.puppetdb') {
103+
run_command(@("CMD"/L), $primary_target)
104+
/opt/puppetlabs/bin/puppet-db export ${shellquote($recovery_directory)}/puppetdb-archive.bin
105+
| CMD
106+
}
107+
98108
## shutdown services
99109
run_command(@("CMD"/L), $primary_target)
100110
systemctl stop pe-console-services pe-nginx pxp-agent pe-puppetserver \
@@ -117,9 +127,6 @@
117127
| CMD
118128
}
119129

120-
# TODO: Use PuppetDB's /pdb/admin/v1/archive API to SAVE data currently in
121-
# PuppetDB. Otherwise we'll completely lose it if/when we restore.
122-
123130
#$database_to_restore.each |Integer $index, Boolean $value | {
124131
$restore_databases.each |$name,$database_targets| {
125132
out::message("# Restoring ${name} database")
@@ -190,8 +197,15 @@
190197
| CMD
191198
}
192199

193-
# TODO: Use PuppetDB's /pdb/admin/v1/archive API to MERGE previously saved
194-
# data into the restored database.
200+
# Use PuppetDB's /pdb/admin/v1/archive API to MERGE previously saved data
201+
# into the restored database.
202+
# TODO: consider adding a heuristic to skip when innappropriate due to size
203+
# or other factors.
204+
if getvar('recovery_opts.puppetdb') {
205+
run_command(@("CMD"/L), $primary_target)
206+
/opt/puppetlabs/bin/puppet-db import ${shellquote($recovery_directory)}/puppetdb-archive.bin
207+
| CMD
208+
}
195209

196210
# Use `puppet infra` to ensure correct file permissions, restart services,
197211
# etc. Make sure not to try and get config data from the classifier, which

0 commit comments

Comments
 (0)