Velero
Jump to navigation
Jump to search
restore.sh
#!/bin/bash
# <source_ns> [destination_ns]
nameSpace=$1
nameSpaceDestination=$2
echo
# Read file names into an array
mapfile -t files_array < <(oc get Backup -n openshift-adp -o name |tac |cut -d/ -f2 |grep -w $nameSpace)
# Display the index number and file name for each file in the array
echo "Backups :"
for ((i=0; i<${#files_array[@]}; i++)); do
echo "$i:${files_array[$i]}"
done
echo
echo "Select index [0]:"
read i
[ -z $i ] &&i=0
backupName="${files_array[$i]}"
[ -z $nameSpaceDestination ] &&nameSpaceDestination=$nameSpace
kubectl get ns $nameSpaceDestination -o name >/dev/null 2>&1 &&nameSpaceDestination=${nameSpaceDestination}-$(echo $RANDOM |md5sum |cut -c1-6 )
OADP_OPERATOR_NAMESPACE=openshift-adp
cat <<EOF |kubectl -n ${OADP_OPERATOR_NAMESPACE} apply -f -
apiVersion: velero.io/v1
kind: Restore
metadata:
name: ${nameSpace}-$(date '+%Y%m%d%H%M')
spec:
backupName: ${backupName}
restorePVs: true
namespaceMapping:
${nameSpace}: ${nameSpaceDestination}
EOF
watch kubectl get all -n ${nameSpaceDestination}