Puppet Plan: complyadm::list_backups
- Defined in:
- plans/list_backups.pp
Summary
List backups created by complyadm::backup.Overview
Use this plan to list the backups in the backup directory available for restore. You can create these backups using complyadm::backup and restore them using complyadm::restore.
7 8 9 10 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 |
# File 'plans/list_backups.pp', line 7
plan complyadm::list_backups() {
run_plan('complyadm::check_bolt_version')
$config = complyadm::config()
$target = $config['roles']['backend']['targets'][0]
without_default_logging() || {
$ls_cmd = "ls --human-readable --format=long ${config['backup_dir']}/comply-backup-*.zip"
$ls_results = run_command($ls_cmd, $target, '_run_as' => 'root', '_catch_errors' => true)
$backups_without_metadata = $ls_results[0].value['stdout'].split("\n").map |$line| {
$fields = $line.split(/\s+/)
Hash.new({
'name' => $fields[8],
'size' => $fields[4],
})
}
$backups = $backups_without_metadata.map |$backup| {
$zipfile = basename($backup['name'])
$dir = $zipfile[0,-('.zip'.length()+1)]
$metadata_cmd = "unzip -p ${backup['name']} ${dir}/metadata.json"
$metadata_results = run_command($metadata_cmd, $target, '_run_as' => 'root', '_catch_errors' => true)
$metadata = $metadata_results[0]['stdout'].parsejson
$backup + { 'version' => $metadata['version'] }
}
if($ls_results.ok) {
out::message("Backup directory '${config['backup_dir']}' on ${target}")
}
out::message(complyadm::backup::format_results($backups))
if(!$ls_results.ok) {
out::message("No backups found in backup directory '${config['backup_dir']}' on ${target}.")
}
}
}
|