Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
if gcs_bucket is provided, use it or fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasser Elsayed committed Jan 27, 2017
1 parent a7dc7fe commit fc3811b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions containers/datalab/content/GCSbackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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"
Expand Down

0 comments on commit fc3811b

Please sign in to comment.