Skip to content

Commit cb2ba63

Browse files
abaysclaude
andcommitted
[b/r] Add backup/restore and OADP data collection
Collect OADP and backup/restore resources to support troubleshooting of OpenStack backup and restore operations. Add openshift-adp to the default namespace list for pod/log/event collection, and introduce a new gather_backup_restore script that collects Velero Backup/Restore CRs, DataUpload/DataDownload, BackupStorageLocation, VolumeSnapshots, VolumeSnapshotClasses, backup/restore label verification, and deployment-stage annotation status. OMC mode support is included. Ref: OSPRH-32043 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8679a70 commit cb2ba63

4 files changed

Lines changed: 174 additions & 0 deletions

File tree

collection-scripts/common.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export SOS_PATH="${BASE_COLLECTION_PATH}/sos-reports"
1616
export SOS_PATH_NODES="${SOS_PATH}/_all_nodes"
1717
export METALLB_NAMESPACE=${METALLB_NAMESPACE:-"metallb-system"}
1818
export RABBITMQ_SELECTOR="app.kubernetes.io/component=rabbitmq"
19+
export OADP_NS="${OADP_NS-openshift-adp}"
1920
declare -a DEFAULT_NAMESPACES=(
2021
"${OSP_NS}"
2122
"${OSP_OPERATORS_NS}"
@@ -27,6 +28,7 @@ declare -a DEFAULT_NAMESPACES=(
2728
"openshift-operators"
2829
"openshift-logging"
2930
"${METALLB_NAMESPACE}"
31+
"${OADP_NS}"
3032
)
3133
export DEFAULT_NAMESPACES
3234

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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

collection-scripts/gather_run

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ else
5353
collect_omc_post
5454
fi
5555

56+
# get backup/restore and OADP resources
57+
if [[ "${OMC}" != "true" ]]; then
58+
source "${DIR_NAME}/gather_backup_restore"
59+
fi
60+
5661
# dump the openstack database
5762
source "${DIR_NAME}/gather_db"
5863

collection-scripts/omc.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ function collect_webhooks_omc {
9898
fi
9999
}
100100

101+
# Gather OADP and backup/restore resources
102+
function collect_backup_restore_omc {
103+
[[ "${OMC}" != "true" ]] && return
104+
105+
if check_namespace "${OADP_NS}"; then
106+
local oadp_resources=(
107+
"backups.velero.io"
108+
"restores.velero.io"
109+
"datauploads.velero.io"
110+
"datadownloads.velero.io"
111+
"backupstoragelocations.velero.io"
112+
"volumesnapshotlocations.velero.io"
113+
"dataprotectionapplications.oadp.openshift.io"
114+
)
115+
for resource in "${oadp_resources[@]}"; do
116+
if oc -n "${OADP_NS}" get "${resource}" &>/dev/null; then
117+
run_bg oc adm inspect "${resource}" -n "${OADP_NS}" --dest-dir="${BASE_COLLECTION_PATH}"
118+
fi
119+
done
120+
fi
121+
122+
if oc get volumesnapshotclasses.snapshot.storage.k8s.io &>/dev/null; then
123+
run_bg oc adm inspect volumesnapshotclasses.snapshot.storage.k8s.io --dest-dir="${BASE_COLLECTION_PATH}"
124+
fi
125+
126+
if oc -n "${OSP_NS}" get volumesnapshots.snapshot.storage.k8s.io &>/dev/null; then
127+
run_bg oc adm inspect volumesnapshots.snapshot.storage.k8s.io -n "${OSP_NS}" --dest-dir="${BASE_COLLECTION_PATH}"
128+
fi
129+
}
130+
101131
# Post processing actions on gathered files
102132
function collect_omc_post {
103133
local CMS="core/configmaps.yaml"
@@ -156,6 +186,7 @@ function collect_omc_inspect {
156186
collect_crs_omc
157187
collect_webhooks_omc
158188
collect_network_resources_omc
189+
collect_backup_restore_omc
159190

160191
wait
161192
}

0 commit comments

Comments
 (0)