从Cloudshell中的另一个项目读取存储桶

时间:2019-03-17 18:52:43

标签: import google-cloud-firestore google-cloud-storage acl

由于Firestore无法克隆项目,因此我试图通过将数据从一个项目复制到GCS存储桶中并将其读取到另一个项目中来达到相同的目的。

具体来说,我使用cloudshell从Firestore项目A导出的数据填充存储桶,并尝试将其导入Firestore项目B。存储桶属于Firestore项目A。

我能够从Firestore项目A导出数据,没有任何问题。当我尝试使用cloudshell命令导入到Firestore项目B中时

gcloud beta firestore import gs://bucketname

我收到错误消息

project-b@appspot.gserviceaccount.com does not have storage.
buckets.get access to bucketname

我在上下搜索了一种为项目B提供访问权限storage.bucket.get的方法,但是没有找到任何可行的方法。

有人可以指出我的做法吗?我浏览过Google文档已经六次了,或者找不到正确的信息,或者不了解我找到的信息。

非常感谢。

2 个答案:

答案 0 :(得分:0)

要从项目B中的项目A导入,项目B中的服务帐户必须对项目A中的Cloud Storage存储桶具有正确的权限。

在您的情况下,服务帐户为:

  • gsutil acl ch -u project-ID@appspot.gserviceaccount.com:OWNER gs://[BUCKET_NAME] gsutil -m acl ch -r -u project-ID@appspot.gserviceaccount.com:OWNER gs://[BUCKET_NAME]

要授予正确的权限,您可以在项目B的Cloud Shell上使用this command

gcloud beta firestore import gs://[BUCKET_NAME]/[EXPORT_PREFIX]

然后,您可以使用firestore import进行导入:

df['bins'] = df.index // n

答案 1 :(得分:0)

我无法使“ sotis”提供的命令正常工作,但是他的回答无疑使我朝正确的方向前进。最终对我有用的命令是:

    gcloud config set project [SOURCE_PROJECT_ID]
    gcloud beta firestore export gs://[BUCKET_NAME]

    gcloud config set project [TARGET_PROJECT_ID]    
    gsutil acl ch -u [RIGHTS_RECIPIENT]:R gs://[BUCKET_NAME]
    gcloud beta firestore import gs://[BUCKET_NAME]/[TIMESTAMPED_DIRECTORY]

位置:

* SOURCE_PROJECT_ID = the name of the project you are cloning
* TARGET_PROJECT_ID = the destination project for the cloning
* RIGHTS_RECIPIENT = the email address of the account to receive read rights
* BUCKET_NAME = the name of the bucket that stores the data.  
      Please note, you have to manually create this bucket before you export to it.  
      Also, make sure the bucket is in the same geographic region as the projects you are working with.
* TIMESTAMPED_DIRECTORY = the name of the data directory automatically created by the "export" command

我确信这不是解决问题的唯一方法,但是它对我有用,并且似乎是我所见过的“最短路径”解决方案。

相关问题