Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 800
Gal Bracha Avatar asked Oct 14 '17 16:10

Gal Bracha


People also ask

Do I need to backup firestore?

You need backups, and as there's no button to do it in Firestore, we're just going to have to do it ourselves. Fortunately, it can now be implemented fairly simply by using a combination of Firebase Functions (to initiate and automate the backups) and Google Cloud Storage (to store them).


1 Answers

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

like image 127
Gal Bracha Avatar answered Nov 09 '22 05:11

Gal Bracha