How to delete Cloud Firestore backup older than 15 days?

Viewed 503

I am doing a backup of the whole Cloud Firestore Database in the storage bucket on the daily basis. As our users are increasing, Firestore cost is also increasing.

Now, I want to delete the backup older than 15 days ago automatically. Is there any way by which I can write a cloud function that automatically deletes backup which is older than 15 days?

3 Answers

Besides the other solutions provided here, you could also add a lifecycle rule on the backup bucket that will delete the objects within it based on their age. You can set a condition that the object will be deleted after 15 days.

Have a look at this GCP documentation article for more information about the Object Lifecycle Management.

For this purpose, you should be having a timestamp(of its creation) on each document.

Then you can write a function to delete the documents whose timestamp is older than 15 days which you can execute every 15 days or so by a Cron Job

Hope it works out!

Related