Hi, I am using GSUTIL installed via GCLOUD SDK and gsutil as a command its working properly, i am able to create buckets and upload files to that bucket. When i try use the same via windows batch file(.bat), its failing with below errors,
Caught non-retryable exception while listing gs://sushanth-07081985/: ServiceException: 401 Anonymous caller does not have storage.objects.list access to sushanth-07081985.
CommandException: Caught non-retryable exception - aborting rsync
Below is my batch file
set gsutil="C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython\python.exe" "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\gsutil\gsutil"
echo Backing up Test Folder
%gsutil% -m rsync -n -r -d -x ".*node_modules.*^|.*\.git.*" ./TestFolder gs://sushanth-07081985
Tried below things after reading variour S.O posts
Executed command gcloud config list --all and saw pass_credentials_to_gsutil as unset, so had set it as false
gcloud config set pass_credentials_to_gsutil false
Created a service account and tried
gcloud auth activate-service-account --key-file codes-20180829-2c7c4b3e24df.json
gsutil config -e (Backed up the .boto file as it said it is going to change it). Here gave the full path of the Service Account JSON file.
After this i was not able to run at all, so tried to undo everthing i had done and it worked as before
- replaced the .boto file which i had backed up earlier.
- gcloud init (reinitialized configuration)
- gcloud config set pass_credentials_to_gsutil true
I am using windows 10, basically i would like to setup a gsutil to use service account to upload files to Cloud storage via a batch job(.bat). It will be good to know any step by step approach.
Thanks
Updated : 25/12/2018 Is below approach is right ?
- Created a Service Account in IAM using the defaults and generated a p12 file
- Ran gsutil config -e command, it had asked for full path of p12 file[D:\BigData\16.GCP\GCS\Private\codes-20180829-d05f0ecb939d.p12] & SA email id(got it from IAM itself)
- It had generated a .boto file with values populated for gs_service_key_file[p12 filepath], gs_service_client_id[SA email id], gs_service_key_file_password[notasecret]
- Went to each buckets and manually added the SA set the role as StorageAdmin
- Had the env. variable BOTO_PATH set to C:\Users\Sushanth.boto
Now it works, would like to know is the above approach correct ?