Hi there,
I am trying to move a specific Firestore collection to Firestore in a different GCP environment. I was able to export it without any issues, but I'm not sure how to import it into Firestore in the different GCP environment.
I referred to the following two documents, but they were not helpful as their purpose was different and they were quite confusing.
it's possible to request the necessary permissions from the owner in the target GCP environment for the import.
Thanks.
To import a Firestore collection into a different GCP environment, you can follow these steps:
Here are the specific commands to perform each step:
To create a Cloud Storage bucket:
gcloud storage buckets create <bucket-name>
To give the Cloud Firestore service agent permission to read from the Cloud Storage bucket:
gsutil iam ch serviceAccount:service-PROJECT_NUMBER@gcp-sa-firestore.iam.gserviceaccount.com:roles/storage.legacyBucketReader,roles/storage.objectViewer gs://<bucket-name>
gsutil cp -r <local-directory>/* gs://<bucket-name>/<path-to-exported-data>
To start an import operation:
gcloud firestore import gs://<bucket-name>/<path-to-exported-data>
products
to a local directory named /tmp/products
, and the exported data has a timestamp in its directory name, you would use the following commands to import it into a Cloud Storage bucket named my-bucket
in the target GCP environment:
gcloud storage buckets create my-bucket
gsutil iam ch serviceAccount:service-PROJECT_NUMBER@gcp-sa-firestore.iam.gserviceaccount.com:roles/storage.legacyBucketReader,roles/storage.objectViewer gs://my-bucket
gsutil cp -r /tmp/products/* gs://my-bucket/products/2023-10-24T12:34:56_789Z
gcloud firestore import gs://my-bucket/products/2023-10-24T12:34:56_789Z
products
collection will be available in Firestore in the target GCP environment.Clarifications:
gcloud firestore import
command requires the path to the exported data in the Cloud Storage bucket, not just the bucket name. Ensure you specify the full path, especially if the exported data directory includes a timestamp.roles/storage.objectViewer
role to read the exported files from the Cloud Storage bucket.gsutil cp
command requires the gs://
prefix for the Cloud Storage bucket path.Additional Notes:
export_documents
or import_documents
. Ensure you're using the appropriate methods or tools for your operations.