google-cloud-platformgcloudgsutil

Check Google Cloud Storage bucket exists via gsutil


I am writing a function to copy data between buckets through gsutil rsync command.

Just want to make sure if source and destination cloud storage bucket exists before starting rsync operation through gsutil.

Is there an existing way to check cloud storage bucket exists via gsutil ?


Solution

  • There is no existing mechanism via gsutil to check if a bucket exists.

    References :

    https://cloud.google.com/storage/docs/gsutil

    https://github.com/GoogleCloudPlatform/gsutil

    We can validate it this way

      gsutil ls | grep "$BUCKET_NAME"
      test $? -ne 0 && echo “Bucket $BUCKET_NAME doesn't exist, Exiting!!" && exit 1