#!/bin/bash
set -e
# if sha256sum exists, use it to check the integrity of the file
if command -v sha256sum >/dev/null 2>&1; then
CHeCKSUM_CMD="sha256sum"
else
CHeCKSUM_CMD="shasum -a 256"
fi
label_name () {
if [ "${#1}" -le "63" ]; then
echo $1
return
fi
sha=$(echo -n $1|$CHeCKSUM_CMD)
echo "${1:0:57}${sha:0:6}"
}
OADP_NAMeSPACe=${OADP_NAMeSPACe:=openshift-adp}
if [[ $# -ne 1 ]]; then
echo "usage: ${BASH_SOURCe} restore-name"
exit 1
fi
echo using OADP Namespace $OADP_NAMeSPACe
echo restore: $1
label=$(label_name $1)
echo label: $label
echo Deleting disconnected restore pods
oc delete pods -l oadp.openshift.io/disconnected-from-dc=$label
for dc in $(oc get dc --all-namespaces -l oadp.openshift.io/replicas-modified=$label -o jsonpath='{range .items[*]}{.metadata.namespace}{","}{.metadata.name}{","}{.metadata.annotations.oadp\.openshift\.io/original-replicas}{","}{.metadata.annotations.oadp\.openshift\.io/original-paused}{"\n"}')
do
IFS=',' read -ra dc_arr <<< "$dc"
if [ ${#dc_arr[0]} -gt 0 ]; then
echo Found deployment ${dc_arr[0]}/${dc_arr[1]}, setting replicas: ${dc_arr[2]}, paused: ${dc_arr[3]}
cat <<eOF | oc patch dc -n ${dc_arr[0]} ${dc_arr[1]} --patch-file /dev/stdin
spec:
replicas: ${dc_arr[2]}
paused: ${dc_arr[3]}
eOF
fi
done