How to back-up Firebase Firestore and Firebase storage bucket

Powolny Marcel
Scalp
Published in
3 min readMar 29, 2019

Hi,

I’m Powolny Marcel, I’m a web developer in Belgium working for SCALP and I’m happy to share with you my first time ever article about Firebase.

This short illustrated article is about making a full backup of your Firestore database + your Firebase storage bucket. At the end you will end up with a Zip file containing all of your Firestore collections & documents + all your media files from your storage bucket.

I wanted to write this article because I wasn’t able to find any precise information on how to do it and I hope it will be useful to someone someday..

I will show you the steps to back up your Firebase Firestore database

1: Download the Google Cloud SDK

https://cloud.google.com/sdk/downloads

(it will allow you to use the gcloud command in the CLI on your machine)

2: Go to your Google cloud console

(be sure that you have selected the good project and that you are logged as the good user)

https://console.cloud.google.com/storage/browser

From there, copy/remember the name of the bucket you would like to use

let’s say we want to use “bucket_name_1”

3: Login to the Google cloud through your CLI

gcloud beta auth login

(it will open up the web browser and ask you to log in to your google account)

4:Execute the export command line (you will maybe have to select your project first)

gcloud beta firestore export gs://NAME_OF_YOUR_BUCKET

gcloud beta firestore export gs://bucket_name_1

(the name could be something like: “bucket_name_1.appspot.com”)

outputUriPrefix targets the folder in your bucket

Once this is done, you will find a new folder in your Firebase Firestore structure containing a dump of your database:

As you can see, the name of the folder matches the name displayed in the CLI

5: That’s it for the database

Now, I will show you the steps to back up your Firebase storage bucket

1: Go to https://console.cloud.google.com

(be sure that you have selected the good project and that you are logged in as the good user)

2:Launch Google cloud shell

3:Display the path of the working folder (useful for later)

pwd

As you can see my pwd (private working directory) is /home/dev_scalp

4: Make a copy of the bucket (beware of the dot at the end)

gsutil cp -r gs://bucket_name_1 .

( this will create a folder named “bucket_name_1” in your pwd)

5: Make a zip file of the folder “bucket_name_1”

zip -r blahblah_my_backup.zip bucket_name_1

6: Change the zip file permission

chmod 777 blahblah_my_backup.zip

7: Download the zip file via the cloud shell

8:Specify the path to the file

9: Click on the download link.

10: Sit back and relax while Google is preparing the file for you.

Thanks for reading.

Powolny Marcel

Scalp.be

--

--