Sunday, March 21, 2021

Automatic Backup Firestore Using Cloud Scheduler Every Day



Doesn't feel it's been a month since I posted last article regarding print using printer bluetooth. The app has been used over one month and It's fine. I haven't had problem but maybe the alignment that doesn't fit right and left doesn't sync. But overrall it's good for my sister business.

If you've firebase firestore for a long time. Maybe you wonder if your data is lost and there's something upredictable happened. We want our data save, but we believe firebase can handle it right. But for the best you need to backup your data to prevent something bad happened. Fortunely firebase supports it with Google Cloud Platform it's possible. 

There are many article that talks about it, even firebase has documentation about it that I'm gonna the link below. It's not hard to do but remember you need to pay to do it. In my case It doesn't cost much because my DB is small I think. It's a few hundreds Kb. So it's still acceptable in my wallet lol. For now I do backup for 24 hours following practice in firebase.

Ok I'm gonna share the way but as I remember, because full detail explanation on link below if you want to take a look. But maybe if you have any question because doesn't work you can comment on this post of course.

First you need to set the access permission to be "Cloud Datastore Import Export Admin" in IAM & Admin. So there are many member. Just choose the one that has suffix "@appspot.gserviceaccount.com".

After that you need to set "Storage Admin" role in your bucket that you want to put the DB backup. And make sure if you create new folder. Make it same regoin with your firestore. Add the role that has suffix "@appspot.gserviceaccount.com". 

Ok the last thing you need to do is creating cloud scheduler using firebase function. The way is there on link below. I'm just gonna paste the firebase function code in here.


Thank you for visiting my simple blog. Have a nice day.

References : https://firebase.google.com/docs/firestore/solutions/schedule-export

No comments:

Post a Comment