Firestore new database - How do I backup

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


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.


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)


I am using the following work-around in order to have daily firestore backups:

I installed this globally: https://www.npmjs.com/package/firestore-backup-restore

I have a cron job that looks like this:

0 12 * * *  cd ~/my/backup/script/folder && ./backup-script.sh

And my backup-script.sh looks like this:

#!/bin/sh

. ~/.bash_profile

export PATH=/usr/local/bin/

dt=$(/bin/date '+%d-%m-%Y %H:%M:%S');
echo "starting backup for $dt"
firestore-backup-restore -a ~/path/to/account/credentials/file.json -B ./backups/"$dt"