Firestore new database - How do I backup

Update July 2018: Cloud Firestore now supports managed import and export of data. See the documentation for more details:

https://firebase.google.com/docs/firestore/manage-data/export-import


[Googler here] No, right now we do not offer a managed backup or import/export service. This is something we will definitely offer in the future, we just did not get it ready for the initial Beta release.

The best way to back up right now is to write your own script using our Java/Python/Node.js/Go server SDKs, it should be fairly straightforward to download all documents from each collection and write them back if you need to.


Local backups

  1. firestore-import-export

This is the one I use for "one-off", local backups, and what I generally recommend. (most straight-forward if you want a single JSON file)

  1. firestore-backup-restore

Drawbacks:

  1. Hasn't been updated in a long time.

Additional options: (not recommended)

  1. python-firebase-admin-firestore-backup

Drawbacks:

  1. Backup only; cannot restore from the backups it creates.
  2. Hasn't been updated in a long time.
  1. firestore-backup

Drawbacks:

  1. Backup only; cannot restore from the backups it creates.

Cloud backups

  1. The official gcloud backup commands.

Drawbacks:

  1. The backup files are difficult/infeasible to parse. (update: how to convert to a json file)
  2. You have to set up the gcloud cli. (update: or use the cloud shell to run the commands)
  3. It doesn't backup locally; instead, it backs up to the cloud, which you can then download. (could also be considered an advantage, depending on what you want)

Note that for the gcloud backup commands, you have multiple options on how to schedule them to run automatically. A few options are shown here.


https://www.npmjs.com/package/firestore-backup

Is a tool that has been created to do just this.

(I did not create it, just adding it here as people will find this question)


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