【问题标题】:Reading bucket from another project in cloudshell从 cloudshell 中的另一个项目读取存储桶
【发布时间】:2019-03-17 18:52:42
【问题描述】:

因为 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 文档,但要么找不到正确的信息,要么不理解我找到的信息。

非常感谢。

【问题讨论】:

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


    【解决方案1】:

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

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

    • project-ID@appspot.gserviceaccount.com

    要授予正确的权限,您可以在项目 B 的 Cloud 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]
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-12
        • 2013-11-01
        相关资源
        最近更新 更多