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

问题描述 投票:0回答:2

因为Firestore没有克隆项目的方法,所以我试图通过将数据从一个项目复制到GCS存储桶并将其读入另一个项目来实现等效。

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

我可以毫无问题地从Firestore项目A导出数据。当我尝试使用cloudshell命令导入Firestore项目B.

gcloud beta firestore import gs://bucketname

我收到错误消息

[email protected] does not have storage.
buckets.get access to bucketname

我已经搜索了一个方法来提供访问权限storage.bucket.get到项目B,但我找不到任何有效的方法。

谁能指出我这是怎么做到的?我已经浏览了几十次谷歌文档,要么找不到正确的信息,要么不理解我找到的信息。

提前谢谢了。

import google-cloud-firestore google-cloud-storage acl
2个回答
0
投票

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

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

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

gsutil acl ch -u [email protected]:OWNER gs://[BUCKET_NAME]
gsutil -m acl ch -r -u [email protected]:OWNER gs://[BUCKET_NAME]

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

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.