|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Collect OADP (OpenShift API for Data Protection) and backup/restore |
| 4 | +# resources for troubleshooting OpenStack backup and restore operations. |
| 5 | + |
| 6 | +if [[ -z "$DIR_NAME" ]]; then |
| 7 | + CALLED=1 |
| 8 | + DIR_NAME=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
| 9 | + source "${DIR_NAME}/common.sh" |
| 10 | +fi |
| 11 | + |
| 12 | +BACKUP_RESTORE_PATH="${BASE_COLLECTION_PATH}/backup-restore" |
| 13 | + |
| 14 | +# OADP resources in the openshift-adp namespace |
| 15 | +function gather_oadp_resources { |
| 16 | + if ! check_namespace "${OADP_NS}"; then |
| 17 | + echo "OADP namespace ${OADP_NS} not found, skipping OADP resource collection" |
| 18 | + return |
| 19 | + fi |
| 20 | + |
| 21 | + local oadp_resources=( |
| 22 | + "backups.velero.io" |
| 23 | + "restores.velero.io" |
| 24 | + "datauploads.velero.io" |
| 25 | + "datadownloads.velero.io" |
| 26 | + "backupstoragelocations.velero.io" |
| 27 | + "volumesnapshotlocations.velero.io" |
| 28 | + "dataprotectionapplications.oadp.openshift.io" |
| 29 | + ) |
| 30 | + |
| 31 | + echo "Gathering OADP resources from ${OADP_NS}" |
| 32 | + for resource in "${oadp_resources[@]}"; do |
| 33 | + if ! /usr/bin/oc -n "${OADP_NS}" get "${resource}" &>/dev/null; then |
| 34 | + continue |
| 35 | + fi |
| 36 | + local short_name |
| 37 | + short_name="${resource%%.*}" |
| 38 | + local resource_path="${BACKUP_RESTORE_PATH}/oadp/${short_name}" |
| 39 | + mkdir -p "${resource_path}" |
| 40 | + for item in $(/usr/bin/oc -n "${OADP_NS}" get "${resource}" -o custom-columns=":metadata.name" --no-headers 2>/dev/null); do |
| 41 | + run_bg /usr/bin/oc -n "${OADP_NS}" get "${resource}" "${item}" -o yaml '>' "${resource_path}/${item}.yaml" |
| 42 | + done |
| 43 | + done |
| 44 | +} |
| 45 | + |
| 46 | +# VolumeSnapshotClass (cluster-scoped) |
| 47 | +function gather_volume_snapshot_classes { |
| 48 | + if ! /usr/bin/oc get volumesnapshotclasses.snapshot.storage.k8s.io &>/dev/null; then |
| 49 | + return |
| 50 | + fi |
| 51 | + |
| 52 | + echo "Gathering VolumeSnapshotClasses" |
| 53 | + local vsc_path="${BACKUP_RESTORE_PATH}/volumesnapshotclasses" |
| 54 | + mkdir -p "${vsc_path}" |
| 55 | + for vsc in $(/usr/bin/oc get volumesnapshotclasses.snapshot.storage.k8s.io -o custom-columns=":metadata.name" --no-headers 2>/dev/null); do |
| 56 | + run_bg /usr/bin/oc get volumesnapshotclasses.snapshot.storage.k8s.io "${vsc}" -o yaml '>' "${vsc_path}/${vsc}.yaml" |
| 57 | + done |
| 58 | +} |
| 59 | + |
| 60 | +# VolumeSnapshots from the openstack namespace |
| 61 | +function gather_volume_snapshots { |
| 62 | + local NS="${1:-$OSP_NS}" |
| 63 | + if ! check_namespace "${NS}"; then |
| 64 | + return |
| 65 | + fi |
| 66 | + if ! /usr/bin/oc -n "${NS}" get volumesnapshots.snapshot.storage.k8s.io &>/dev/null; then |
| 67 | + return |
| 68 | + fi |
| 69 | + |
| 70 | + echo "Gathering VolumeSnapshots from ${NS}" |
| 71 | + local vs_path="${BACKUP_RESTORE_PATH}/volumesnapshots/${NS}" |
| 72 | + mkdir -p "${vs_path}" |
| 73 | + for vs in $(/usr/bin/oc -n "${NS}" get volumesnapshots.snapshot.storage.k8s.io -o custom-columns=":metadata.name" --no-headers 2>/dev/null); do |
| 74 | + run_bg /usr/bin/oc -n "${NS}" get volumesnapshots.snapshot.storage.k8s.io "${vs}" -o yaml '>' "${vs_path}/${vs}.yaml" |
| 75 | + done |
| 76 | +} |
| 77 | + |
| 78 | +# Backup/restore label verification: which resources are labeled for backup |
| 79 | +# and restore, grouped by restore order |
| 80 | +function gather_backup_restore_labels { |
| 81 | + local NS="${1:-$OSP_NS}" |
| 82 | + if ! check_namespace "${NS}"; then |
| 83 | + return |
| 84 | + fi |
| 85 | + |
| 86 | + echo "Gathering backup/restore label summary from ${NS}" |
| 87 | + local labels_path="${BACKUP_RESTORE_PATH}/labels/${NS}" |
| 88 | + mkdir -p "${labels_path}" |
| 89 | + |
| 90 | + run_bg /usr/bin/oc -n "${NS}" get all,secrets,configmaps,pvc,network-attachment-definitions \ |
| 91 | + -l backup.openstack.org/restore=true \ |
| 92 | + -o custom-columns='KIND:.kind,NAME:.metadata.name,RESTORE-ORDER:.metadata.labels.backup\.openstack\.org/restore-order,CATEGORY:.metadata.labels.backup\.openstack\.org/category' \ |
| 93 | + '>' "${labels_path}/restore-labeled-resources.log" |
| 94 | + |
| 95 | + run_bg /usr/bin/oc -n "${NS}" get pvc \ |
| 96 | + -l backup.openstack.org/backup=true \ |
| 97 | + -o custom-columns='NAME:.metadata.name,RESTORE:.metadata.labels.backup\.openstack\.org/restore,RESTORE-ORDER:.metadata.labels.backup\.openstack\.org/restore-order' \ |
| 98 | + '>' "${labels_path}/backup-labeled-pvcs.log" |
| 99 | + |
| 100 | + # CRDs with backup.openstack.org labels |
| 101 | + run_bg /usr/bin/oc get crd -l backup.openstack.org/restore=true \ |
| 102 | + -o custom-columns='NAME:.metadata.name,RESTORE-ORDER:.metadata.labels.backup\.openstack\.org/restore-order,CATEGORY:.metadata.labels.backup\.openstack\.org/category' \ |
| 103 | + '>' "${labels_path}/backup-restore-crds.log" |
| 104 | + |
| 105 | + # Resources with annotation overrides |
| 106 | + run_bg /usr/bin/oc -n "${NS}" get secrets,configmaps,pvc \ |
| 107 | + -o json '|' jq -r \ |
| 108 | + '.items[] | select(.metadata.annotations["backup.openstack.org/restore"] // .metadata.annotations["backup.openstack.org/restore-order"]) | "\(.kind)/\(.metadata.name) restore=\(.metadata.annotations["backup.openstack.org/restore"] // "unset") order=\(.metadata.annotations["backup.openstack.org/restore-order"] // "unset")"' \ |
| 109 | + '>' "${labels_path}/annotation-overrides.log" |
| 110 | +} |
| 111 | + |
| 112 | +# OpenStackControlPlane deployment-stage annotation |
| 113 | +function gather_deployment_stage { |
| 114 | + local NS="${1:-$OSP_NS}" |
| 115 | + if ! check_namespace "${NS}"; then |
| 116 | + return |
| 117 | + fi |
| 118 | + |
| 119 | + local stage_path="${BACKUP_RESTORE_PATH}/deployment-stage" |
| 120 | + mkdir -p "${stage_path}" |
| 121 | + |
| 122 | + run_bg /usr/bin/oc -n "${NS}" get openstackcontrolplane \ |
| 123 | + -o custom-columns='NAME:.metadata.name,DEPLOYMENT-STAGE:.metadata.annotations.core\.openstack\.org/deployment-stage,INFRA-READY:.status.conditions[?(@.type=="OpenStackControlPlaneInfrastructureReady")].status,READY:.status.conditions[?(@.type=="Ready")].status' \ |
| 124 | + '>' "${stage_path}/controlplane-stage.log" |
| 125 | +} |
| 126 | + |
| 127 | +echo "Gathering backup/restore resources" |
| 128 | +mkdir -p "${BACKUP_RESTORE_PATH}" |
| 129 | + |
| 130 | +gather_oadp_resources |
| 131 | +gather_volume_snapshot_classes |
| 132 | +gather_volume_snapshots "${OSP_NS}" |
| 133 | +gather_backup_restore_labels "${OSP_NS}" |
| 134 | +gather_deployment_stage "${OSP_NS}" |
| 135 | + |
| 136 | +[[ $CALLED -eq 1 ]] && wait_bg |
0 commit comments