Search code examples
backupgoogle-cloud-firestore

Firestore new database - How do I backup


Does the google firestore database service provides a backup? If so, how do I backup the database and how do I restore in case of an error?


Solution

  • Update: It is now possible to backup and restore Firebase Firestore using Cloud Firestore managed export and import service

    You do it by:

    1. Create a Cloud Storage bucket for your project - Make sure it's a regional in us-central1 or 2 / multi regional type of bucket

    2. Set up gcloud for your project using gcloud config set project [PROJECT_ID]

    EXPORT

    Export all by calling gcloud firestore export gs://[BUCKET_NAME] Or Export a specific collection using gcloud firestore export gs://[BUCKET_NAME] --collection-ids='[COLLECTION_ID_1]','[COLLECTION_ID_2]'

    IMPORT

    Import all by calling gcloud firestore import gs://[BUCKET_NAME]/[EXPORT_PREFIX]/ where [BUCKET_NAME] and [EXPORT_PREFIX] point to the location of your export files. For example - gcloud firestore import gs://exports-bucket/2017-05-25T23:54:39_76544/

    Import a specific collection by calling: gcloud firestore import --collection-ids='[COLLECTION_ID_1]','[COLLECTION_ID_2]' gs://[BUCKET_NAME]/[EXPORT_PREFIX]/

    Full instructions are available here: https://firebase.google.com/docs/firestore/manage-data/export-import