How to backup Google Firestore

Pete Casson
2 min readJun 3, 2021
Google Cloud Firestore

Google Firestore is a fantastic NoSQL database with incredible power and flexibility. However, there’s no easy way to backup the database in the Firebase Console, (Hint: check out the GCP Console instead) and sometimes you want to programmatically export it.

To backup Firestore you’ll need to create your own script, this can be used in Cloud Functions and scheduled to run daily, hourly, whenever really.

One word of caution, exporting data incurs one read operation per document exported. Just be mindful when you schedule this as you can rack up a bill quickly.

OK let’s go!

It’s pretty simple really, we’re using the exportDocuments function from the firestore library. I’m using NodeJS for this but any of the supported language will work in a similar fashion. You’ll need to create a storage bucket if you haven’t already.

Just pass three params to the function and you’re good to go.

projectName: String = Name of the Google Cloud Project
collections: Array[String] = An array of collection names to backup. Pass an empty array to backup all collections.
storageBucket: String = The storage bucket to save the export to, a new date stamped folder will be created.

You can then copy the folder to an external storage location to have an ‘offsite’ backup.

--

--

Pete Casson

CTO, founder, speaker and general geek. Constantly looking to make technology simple and accessible.