Skip to content

Commit

Permalink
logical-backup:gcs_upload: try to use gcp metadata if LOGICAL_GOOGLE_…
Browse files Browse the repository at this point in the history
…APPLICATION_CREDENTIALS is not set
  • Loading branch information
ggramal committed Jan 9, 2025
1 parent 46d5ebe commit 238f941
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion logical-backup/dump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,21 @@ function aws_upload {
function gcs_upload {
PATH_TO_BACKUP=gs://$LOGICAL_BACKUP_S3_BUCKET"/"$LOGICAL_BACKUP_S3_BUCKET_PREFIX"/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"$(date +%s).sql.gz

gsutil -o Credentials:gs_service_key_file=$LOGICAL_BACKUP_GOOGLE_APPLICATION_CREDENTIALS cp - "$PATH_TO_BACKUP"
#Set local LOGICAL_GOOGLE_APPLICATION_CREDENTIALS to nothing or
#value of LOGICAL_GOOGLE_APPLICATION_CREDENTIALS env var. Needed
#because `set -o nounset` is globally set
local LOGICAL_BACKUP_GOOGLE_APPLICATION_CREDENTIALS=${LOGICAL_BACKUP_GOOGLE_APPLICATION_CREDENTIALS:-}

GSUTIL_OPTIONS=("-o" "Credentials:gs_service_key_file=$LOGICAL_BACKUP_GOOGLE_APPLICATION_CREDENTIALS")

#If GOOGLE_APPLICATION_CREDENTIALS is not set try to get
#creds from metadata
if [[ -z $LOGICAL_BACKUP_GOOGLE_APPLICATION_CREDENTIALS ]]
then
GSUTIL_OPTIONS[1]="GoogleCompute:service_account=default"
fi

gsutil ${GSUTIL_OPTIONS[@]} cp - "$PATH_TO_BACKUP"
}

function upload {
Expand Down

0 comments on commit 238f941

Please sign in to comment.