项目之间的Firestore和Storage Bucket导出/导入 [英] Firestore and Storage Bucket Export/Import between Projects

查看:82
本文介绍了项目之间的Firestore和Storage Bucket导出/导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在当前的Google Cloud CLI Beta功能中,可以选择导入和导出Firestore数据. https://firebase.google.com/docs/firestore/manage-data /export-import

So in the current Beta Functions of the Google Cloud CLI there is a option to import and export Firestore data. https://firebase.google.com/docs/firestore/manage-data/export-import

现在,我进行了导出到存储桶"操作,一切正常,然后再次将其导入,效果也很好.现在我有2个不同的项目,想将备份导入到另一个项目中,这可能吗?如果我也只需要一个项目的计费帐户,那会很好.

Now I made a Export into a Bucket, all worked fine and imported it again, worked well too. Now I have 2 different Projects and wanna import the backup into a different Project, is that possible? Would be good if I only need a billing Account for one Project too.

文档中的这一行说明了可能的

This line in the Docs says its possible

一旦您在Cloud Storage中导出了文件,就可以导入文档 将这些文件中的文件放回您的项目或另一个项目中.

Once you have export files in Cloud Storage, you can import documents in those files back into your project or to another project.

但是文档没有涵盖其完成情况如何?

But the Docs dont cover how exactly its done?

推荐答案

可以在项目之间导入/导出.以下是对我有用的步骤:

It is possible to import/export between projects. Here are the steps that have worked for me:

首先,请确保已安装gcloud命令行工具.设置说明, 可以在Firebase的文档中阅读有关导出/导入过程的完整信息. 关于 Firestore导出和导入的页面.

First, make sure that the gcloud command line tool is installed. Instructions on set up, and complete information on the export/import process can be read on Firebase's documentation page about Firestore Export and Import.

在继续之前,将gcloud项目设置为您要从中获取数据的项目:

Before continuing, set the gcloud project to the project from which you want to source your data:

gcloud config set project [PROJECT_ID]

然后,使用 Google Cloud Console 网络应用程序,确保已在 Cloud Storage 存储桶上创建了 将成为数据的的项目.

Then, using the Google Cloud Console web application, make sure that a Cloud Storage bucket has been created on the project that will be the source of the data.

例如,对于源存储桶,您可以创建一个存储桶,例如:

For example, for the source bucket, you might create a bucket such as:

gs://my-source-project-export.

只要选择独特的东西,您就可以为存储桶命名.

You can name the bucket whatever you want, as long as you choose something unique.

然后可以使用命令完成源数据的导出.例如,如果您要导出 仅将camerasradios集合添加到my-source-project-export存储桶中,并带有 注明日期的目录以标识导出,您可以包括可选的collection-ids标志,如下所示:

Exporting of the source data can then be completed using a command. For example, if you wanted to export just the cameras and radios collections to your my-source-project-export bucket, with a dated directory to identify the export, you include the optional collection-ids flag, as follows:

gcloud beta firestore export gs://my-source-project-export/export-20190113_2109 --collection-ids='cameras','radios'

省略该标志将复制所有集合.

Omitting the flag would copy ALL the collections.

gcloud CLI工具应该可以成功完成导出.

The gcloud CLI tool should complete the export without issue.

现在,要完成导入,我们首先将gcloud项目切换到 target 以获取数据:

Now, to complete the import, we first switch the gcloud project to the target for our data:

gcloud config set project [PROJECT_ID]

然后,我们可以尝试导入:

Then, we can attempt the import:

gcloud beta firestore import --collection-ids='cameras','radios' gs://my-source-project-export/export-20190113_2109

由于权限问题,该操作可能会失败.如果是这样,它将报告需要哪个服务帐户 进入水桶.要解决权限问题,您只需使用 Google Cloud Console存储浏览器来管理 source 存储桶的权限.必须将所需的服务帐户添加到成员列表中,并带有 角色Storage Admin.

The operation may fail due to permission issues. If so, it will report which service account needs to have access to the bucket. To resolve the permission issues, you can simply using the Google Cloud Console Storage Browser to administer the permissions for the source bucket. The required service account must be added to the members list with the role Storage Admin.

更正权限后,可以重新尝试该操作.对于长时间运行的操作,列表 可以使用以下命令检索操作及其状态的信息:

Once the permissions are corrected, the operation can be re-attempted. For long running operations, a list of operations and their statuses can be retrieved using the following command:

gcloud beta firestore operations list

一旦导入完成,最好取消授予服务帐户的权限(如果有的话),以避免任何不必要的安全问题.

Once the import is completed, it may be wise to revoke the permissions granted to the service account, if any, to avoid any unwanted security issues.

希望有帮助.

这篇关于项目之间的Firestore和Storage Bucket导出/导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆