gcp gcs - ghdrako/doc_snipets Wiki

Create a cloud storage bucket

gsutil mb -p [PROJECT_ID] gs://[BUCKET_NAME]

Recursively copy all your objects from the source bucket to the destination bucket

gsutil cp -r gs://SOURCE_BUCKET/* gs://DESTINATION_BUCKET
gsutil -m cp -r gs://gcs-bucket-name/batch gcs-bucket-name-local

-m option - perform a parallel multi-threaded/multi-processing copy

List buckets

gsutil ls

Viewing the IAM policy for a bucket

gsutil iam get gs://BUCKET_NAME
gcloud projects get-iam-policy my_project
gcloud projects add-iam-policy-binding xxx --member "serviceAccount:[email protected]" --role "roles/storage.objectViewer"

Versioning

gsutil versioning set (on|off) gs://<bucket_name>...
gsutil versioning get gs://<bucket_name>...   # Enable or suspend 

# When Bucket versioning is enabled, we can get all versions of a file by typing
gsutil ls -a gs://path/to/file

Make your object publicly accessible

gsutil acl ch -u AllUsers:R gs://YOUR-BUCKET-NAME/ada.jpg

Remove public access

gsutil acl ch -d AllUsers gs://YOUR-BUCKET-NAME/ada.jpg

Delete objects

gsutil rm gs://YOUR-BUCKET-NAME/ada.jpg