Velero: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=== restore.sh === <syntaxhighlight lang="bash"> #!/bin/bash # <source_ns> [destination_ns] nameSpace=$1 nameSpaceDestination=$2 echo # Read file names into an array mapfil...") |
No edit summary |
||
Line 41: | Line 41: | ||
watch kubectl get all -n ${nameSpaceDestination} | watch kubectl get all -n ${nameSpaceDestination} | ||
</syntaxhighlight> | |||
=== backup.sh === | |||
<syntaxhighlight lang="bash"> | |||
#!/bin/bash | |||
# <source_ns> | |||
export nameSpace=$1 | |||
backupSuffix="-$(date '+%Y%m%d-%H-%M')" | |||
backupName=${nameSpace}${backupSuffix} | |||
export OADP_OPERATOR_NAMESPACE=openshift-adp | |||
cat <<EOF |kubectl -n ${OADP_OPERATOR_NAMESPACE} apply -f - |cut -d' ' -f1 |xargs watch kubectl -o jsonpath='{.status.phase}' -n ${OADP_OPERATOR_NAMESPACE} get | |||
apiVersion: velero.io/v1 | |||
kind: Backup | |||
metadata: | |||
name: ${backupName} | |||
spec: | |||
defaultVolumesToRestic: true | |||
snapshotVolumes: true | |||
includedNamespaces: | |||
- ${nameSpace} | |||
storageLocation: velero-1 | |||
ttl: 240h0m0s | |||
volumeSnapshotLocations: | |||
- velero-1 | |||
EOF | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 10:58, 17 July 2023
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}
backup.sh
#!/bin/bash
# <source_ns>
export nameSpace=$1
backupSuffix="-$(date '+%Y%m%d-%H-%M')"
backupName=${nameSpace}${backupSuffix}
export OADP_OPERATOR_NAMESPACE=openshift-adp
cat <<EOF |kubectl -n ${OADP_OPERATOR_NAMESPACE} apply -f - |cut -d' ' -f1 |xargs watch kubectl -o jsonpath='{.status.phase}' -n ${OADP_OPERATOR_NAMESPACE} get
apiVersion: velero.io/v1
kind: Backup
metadata:
name: ${backupName}
spec:
defaultVolumesToRestic: true
snapshotVolumes: true
includedNamespaces:
- ${nameSpace}
storageLocation: velero-1
ttl: 240h0m0s
volumeSnapshotLocations:
- velero-1
EOF