Skip to content

Commit

Permalink
use rsync instead of cp, added download progress option
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisVQ committed Mar 25, 2024
1 parent a36316c commit 099c685
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sonarqube/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ set -eu

NAMESPACE="ods"
BACKUP_DIR="."
PROGRESS=false

function usage {
printf "usage: %s [options]\n" "$0"
printf "\t-h|--help\tPrints the usage\n"
printf "\t-v|--verbose\tVerbose output\n"
printf "\t-b|--backup-dir\tLocation of backup directory\n"
printf "\t-n|--namespace\tNamespace (defaults to '%s')\n" "${NAMESPACE}"
printf "\t-p|--progress\tShow progress during transfer (defaults to '%s')\n" "${PROGRESS}"
}

while [[ "$#" -gt 0 ]]; do case $1 in
Expand All @@ -23,6 +25,9 @@ while [[ "$#" -gt 0 ]]; do case $1 in
-n=*|--namespace=*) NAMESPACE="${1#*=}";;
-n|--namespace) NAMESPACE="$2"; shift;;

-p=*|--progress=*) PROGRESS="${1#*=}";;
-p|--progress) PROGRESS="$2"; shift;;

*) echo "Unknown parameter passed: $1"; usage; exit 1;;
esac; shift; done

Expand All @@ -32,12 +37,11 @@ if ! oc whoami > /dev/null; then
fi

# Dump database
destinationFile="${BACKUP_DIR}/sonarqube.sql"
podWithPrefix=$(oc get pods -n "${NAMESPACE}" --selector name=sonarqube-postgresql --no-headers -o name)
pod=${podWithPrefix#"pod/"}
oc rsh -n "${NAMESPACE}" "pod/${pod}" bash -c "mkdir -p /var/lib/pgsql/backup && pg_dump sonarqube > /var/lib/pgsql/backup/sonarqube.sql"
# Copy export
oc -n "${NAMESPACE}" cp "${pod}:/var/lib/pgsql/backup/sonarqube.sql" "${destinationFile}"
oc -n "${NAMESPACE}" rsync --progress=${PROGRESS} "${pod}:/var/lib/pgsql/backup/sonarqube.sql" "${BACKUP_DIR}"
# Delete export in pod
oc rsh -n "${NAMESPACE}" "pod/${pod}" bash -c "rm /var/lib/pgsql/backup/sonarqube.sql"

Expand Down

0 comments on commit 099c685

Please sign in to comment.