gcp gcs gsutil - ghdrako/doc_snipets GitHub Wiki

przenoszenie danych miedzy bucketami

gsutil cp gs://bucket1/obj gs://bucket2/obj2
gsutil cp -r gs://[bucket1]/* gs://[bucket2]

Google storage transfer

https://cloud.google.com/storage-transfer/docs/cloud-storage-to-cloud-storage#gcloud-cli

RSync connent

gsutil -m rsync -r gs://bucket-source/dir gs://bucket-destination/dir

Uwaga!!! bucket powinien byc jako ostatni. Wskazanie projektu jako -p <project> powinno byc przed

gsutil ls -p <project> gs://<bucket>

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

Rename

gsutil -m mv gs://my_bucket/oldprefix gs://my_bucket/newprefix
gsutil ls gs://your-bucket/**.jpg | sed 's/\(.*\).jpg/gsutil mv & \1/'
-----------------
gsutil ls gs://your-bucket/*/**.loaded > bucket_list.txt  
awk '{print "gsutil mv "$1" "$1"xxx"}' bucket_list.txt  > bucket_list_awk.txt  # W drugim wystapieniu dodajemy cos do extension by latwo mozna bylo je usunac np sed-em   usuwamy .loadedxxx
# uruchomic polecenia z bucket_list_awk.txt

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
⚠️ **GitHub.com Fallback** ⚠️