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

Reading bucket from another project in cloudshell

由于 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 文档六次,要么没有找到正确的信息,要么不理解我找到的信息。

非常感谢。

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

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

  • project-ID@appspot.gserviceaccount.com

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

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]

然后,您可以使用 firestore import:

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

我无法让 "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

我确信这不是解决问题的唯一方法,但它对我有用并且似乎是我见过的 "shortest path" 解决方案。