|
| 1 | +plan peadm::test_restore ( |
| 2 | + # This plan should be run on the primary server |
| 3 | + Peadm::SingleTargetSpec $target, |
| 4 | + |
| 5 | + # Path to the recovery tarball |
| 6 | + Pattern[/.*\.tar\.gz$/] $input_file, |
| 7 | + |
| 8 | + # boolean flag to indicate clean target before restore |
| 9 | + Boolean $clean_target = false, |
| 10 | +) { |
| 11 | + peadm::assert_supported_bolt_version() |
| 12 | + |
| 13 | + # prior to running this plan the user will have something like this: |
| 14 | + # perform a backup on the source PE server: |
| 15 | + # bolt plan run peadm::backup backup_type=migration -t festive-gantlet.delivery.puppetlabs.net --no-host-key-check |
| 16 | + # |
| 17 | + # download the backup file locally: |
| 18 | + # bolt file download /tmp/pe-backup-2025-01-30T091722Z.tar.gz /tmp --targets festive-gantlet.delivery.puppetlabs.net --no-host-key-check |
| 19 | + # |
| 20 | + # upload the backup file to the target PE server: |
| 21 | + # bolt file upload /tmp/festive-gantlet.delivery.puppetlabs.net/pe-backup-2025-01-30T091722Z.tar.gz /tmp --targets inspiring-reign.delivery.puppetlabs.net --no-host-key-check |
| 22 | + # |
| 23 | + # install PE on the target server (using the "code_manager_auto_configure": true parameter) |
| 24 | + # bolt plan run peadm::install primary_host=inspiring-reign.delivery.puppetlabs.net replica_host=inspiring-reign.delivery.puppetlabs.net code_manager_auto_configure=true --no-host-key-check |
| 25 | + # |
| 26 | + # run this plan to restore the backup on the target PE server: |
| 27 | + # bolt plan run peadm::test_restore clean_target=false input_file=/tmp/festive-gantlet.delivery.puppetlabs.net/pe-backup-2025-01-30T135004Z.tar.gz target=inspiring-reign.delivery.puppetlabs.net --no-host-key-check |
| 28 | + # |
| 29 | + |
| 30 | + $params = loadjson('params.json') |
| 31 | + $primary_host = $params['primary_host'] |
| 32 | + out::message("params: ${params}") |
| 33 | + out::message("primary_host:${primary_host}.") |
| 34 | +
|
| 35 | + # check param to see if we need to do an uninstall/install on the target |
| 36 | + if $clean_target { |
| 37 | + out::message('Cleaning target before restore') |
| 38 | + run_plan('peadm::uninstall', $target) |
| 39 | + run_plan('peadm::install', $params) |
| 40 | + #run_plan('peadm::install', $target, { 'params' => '@params.json' }) |
| 41 | + } else { |
| 42 | + out::message('Skipping clean target before restore') |
| 43 | + } |
| 44 | +
|
| 45 | + # delete the file on the target first in case it is there |
| 46 | + $file_name = basename($input_file) |
| 47 | + $dir_name = $file_name[0,-8] |
| 48 | + out::message("Deleting /tmp/${file_name} and /tmp/${dir_name} on ${target}") |
| 49 | + run_command("rm -rf /tmp/${file_name}", $target) |
| 50 | + run_command("rm -rf /tmp/${dir_name}", $target) |
| 51 | +
|
| 52 | + # copy the file over from the bolt controller to the target |
| 53 | + out::message("Copying ${input_file} to /tmp/${file_name} on ${target}") |
| 54 | + upload_file($input_file, "/tmp/${file_name}", $target) |
| 55 | +
|
| 56 | + # kick off the restore plan on the target |
| 57 | + out::message("Running peadm::restore on ${target}") |
| 58 | + run_plan('peadm::restore', $target, { 'input_file' => "/tmp/${file_name}", 'restore_type' => 'migration' }) |
| 59 | +
|
| 60 | + # # add replica back |
| 61 | + # run_plan('peadm::add_replica', |
| 62 | + # primary_host => $primary_host, |
| 63 | + # replica_host => $replica_host, |
| 64 | + # replica_postgresql_host => undef, |
| 65 | + # ) |
| 66 | +} |
0 commit comments