Check the cli tool for the backups copy
set -o errexit
tmp_dir=$(mktemp -d)
+ctrl=""
+
+check_ctrl() {
+ if [ -x "$(command -v oc)" ]; then
+ ctrl="oc"
+ elif [ -x "$(command -v kubectl)" ]; then
+ ctrl="kubectl"
+ else
+ echo "[ERROR] Neither <oc> nor <kubectl> client found"
+ exit 1
+ fi
+}
usage() {
cat - <<-EOF
@@ -9,7 +21,7 @@ usage() {
OPTIONS:
<backup-name> the backup name
- it can be obtained with the "kubectl get pxc-backup" command
+ it can be obtained with the "$ctrl get pxc-backup" command
<local/dir> the name of destination directory on local machine
EOF
exit 1
@@ -18,8 +30,8 @@ usage() {
get_backup_pvc() {
local backup=$1
- if kubectl get "pxc-backup/$backup" 1>/dev/null 2>/dev/null; then
- kubectl get "pxc-backup/$backup" -o jsonpath='{.status.volume}'
+ if $ctrl get "pxc-backup/$backup" 1>/dev/null 2>/dev/null; then
+ $ctrl get "pxc-backup/$backup" -o jsonpath='{.status.volume}'
else
# support direct PVC name here
echo -n "$backup"
@@ -48,7 +60,7 @@ check_input() {
mkdir -p "$dest_dir"
fi
- if ! kubectl get "pvc/$backup_pvc" 1>/dev/null; then
+ if ! $ctrl get "pvc/$backup_pvc" 1>/dev/null; then
printf "[ERROR] '%s' PVC doesn't exists.\n\n" "$backup_pvc"
usage
fi
@@ -61,8 +73,8 @@ check_input() {
start_tmp_pod() {
local backup_pvc=$1
- kubectl delete pod/backup-access 2>/dev/null || :
- cat - <<-EOF | kubectl apply -f -
+ $ctrl delete pod/backup-access 2>/dev/null || :
+ cat - <<-EOF | $ctrl apply -f -
apiVersion: v1
kind: Pod
metadata:
@@ -82,7 +94,7 @@ start_tmp_pod() {
EOF
echo -n Starting pod.
- until kubectl get pod/backup-access -o jsonpath='{.status.containerStatuses[0].ready}' 2>/dev/null | grep -q 'true'; do
+ until $ctrl get pod/backup-access -o jsonpath='{.status.containerStatuses[0].ready}' 2>/dev/null | grep -q 'true'; do
sleep 1
echo -n .
done
@@ -93,12 +105,12 @@ copy_files() {
local dest_dir=$1
echo "Downloading started"
- kubectl cp backup-access:/backup/ "${dest_dir%/}/"
+ $ctrl cp backup-access:/backup/ "${dest_dir%/}/"
echo "Downloading finished"
}
stop_tmp_pod() {
- kubectl delete pod/backup-access
+ $ctrl delete pod/backup-access
}
check_md5() {
@@ -114,6 +126,7 @@ main() {
local dest_dir=$2
local backup_pvc
+ check_ctrl
enable_logging
backup_pvc=$(get_backup_pvc "$backup")
check_input "$backup_pvc" "$dest_dir"
