From fc3811b3fb19f32bb3c414accd26f59aa24e360e Mon Sep 17 00:00:00 2001 From: Yasser Elsayed Date: Thu, 26 Jan 2017 17:31:28 -0800 Subject: [PATCH] if gcs_bucket is provided, use it or fail --- containers/datalab/content/GCSbackup.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/containers/datalab/content/GCSbackup.sh b/containers/datalab/content/GCSbackup.sh index d4d903423..bd9429e55 100755 --- a/containers/datalab/content/GCSbackup.sh +++ b/containers/datalab/content/GCSbackup.sh @@ -96,10 +96,20 @@ timestamp=$(date "+%Y%m%d%H%M%S") project_id=${project_id:-$VM_PROJECT} zone=${zone:-${VM_ZONE}} machine_name=${machine_name:-$VM_NAME} -default_bucket="${project_id}.appspot.com" tag="${tag:-backup}" num_backups=${num_backups:-10} -gcs_bucket=${gcs_bucket:-$default_bucket} + +# If no bucket is provided, try $project_id.appspot.com, then try $project_id +if [ -z "${gcs_bucket}" ]; then + default_bucket="${project_id}.appspot.com" + echo "Will use ${default_bucket} for bucket name" + gsutil ls "gs://${default_bucket}" &>/dev/null && gcs_bucket="${default_bucket}" || { + gcs_bucket=${project_id} + echo "Could not find ${default_bucket}. Next will use ${gcs_bucket} for bucket name" + gsutil mb gs://"${gcs_bucket}" || true + } +fi + backup_path=`readlink -f "${backup_path:-.}"` echo "tag: ${tag}" @@ -120,16 +130,6 @@ if [[ -z $machine_name || -z $project_id || -z $zone ]]; then exit 1 fi -# test and create bucket if necessary -gsutil ls gs://${gcs_bucket} &>/dev/null || { - echo "Bucket '${gcs_bucket}' was not found. Creating it.." - gsutil mb gs://"${gcs_bucket}" || { - echo "Bucket '${gcs_bucket}' coult not be created. Will try bucket name ${project_id}" - gcs_bucket="${project_id}" - gsutil mb gs://"${gcs_bucket}" || true - } -} - # create an archive of the backup path archive_name=$(mktemp -d)"/archive.tar" echo "Creating archive: $archive_name"