Puppet Plan: cd4peadm::restore

Defined in:
plans/restore.pp

Summary

Restore CD4PE

Overview

Given a target with a fresh CD4PE installation of the same version as the backup, this plan will restore the database and docker volumes from a given backup zip archive.

This plan will fail if the version recorded in the backup’s metadata does not match the current module version, or if it does not match the version of the install the user is trying to apply the backup to.

Parameters:

  • backup (String[1])

    The name of the backup created by cd4peadm::backup. For example “cd4pe-backup-2023-04-05-01-01-01-01.zip”



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'plans/restore.pp', line 11

plan cd4peadm::restore(
  String[1] $backup,
) {
  run_plan('cd4peadm::check_bolt_version')

  $config = cd4peadm::config()
  $target = $config['roles']['backend']['targets'][0]
  $runtime = $config['runtime']

  without_default_logging() || {
    $preflight_results = run_plan(
      'cd4peadm::restore::preflight',
      'config' => $config,
      'backup' => $backup,
    )

    if($preflight_results != '') {
      fail_plan($preflight_results)
    }
  }

  # bring down pfi, query, and ui
  apply_prep($target, { '_run_as' => 'root' })
  $stop_apply_options = {
    '_run_as' => 'root',
    '_description' => 'Stop CD4PE services',
  }

  apply($target, $stop_apply_options) {
    service { "${runtime}-pipelinesinfra":
      ensure => stopped,
    }
    service { "${runtime}-query":
      ensure => stopped,
    }
    service { "${runtime}-ui":
      ensure => stopped,
    }
  }

  # Gather database information and run the restore task
  $db_role = $config['roles']['database']['services']['postgres']

  $database_info = Cd4peadm::Support_bundle::Database_info.new({
      'container_name' => $db_role['container']['name'],
      'database_user'  => $db_role['admin_db_username'],
  })

  $host = $config['roles']['backend']['targets'][0]
  $restore_result = run_task(
    'cd4peadm::restore',
    # TODO: Currently only supports a single target
    $host,
    {
      'runtime'        => $runtime,
      'backup_dir'     => $config['backup_dir'],
      'backup_archive' => $backup,
      'database_info'  => $database_info,
      'image'          => $config['images']['pipelinesinfra'],
      '_run_as'        => 'root',
      '_catch_errors'  => true,
    }
  )

  if($restore_result[0].ok) {
    $restore_result[0].value['warnings'].each |$warning| {
      out::message($warning)
    }
    out::message($restore_result[0].value['message'])
  } else {
    $error_message = @("ERROR")
      Restore failed:
        ${restore_result[0].value['message']}
        ${restore_result[0].value['error']}
      Check the bolt-debug.log for additional details.
      | ERROR
    fail_plan($error_message)
  }

  # Restart the services
  $start_apply_options = {
    '_run_as' => 'root',
    '_description' => 'Start CD4PE services',
  }
  apply($target, $start_apply_options) {
    service { "${runtime}-pipelinesinfra":
      ensure => running,
    }
    service { "${runtime}-query":
      ensure => running,
    }
    service { "${runtime}-ui":
      ensure => running,
    }
  }

  out::message('Restore complete. Note that if the database passwords have been changed, you will need to run')
  out::message('`bolt plan run cd4peadm::apply_configuration` to update the passwords and allow the services to properly start.')
}