Firestore backup with GitHub Actions

I needed a way to perform automated backup for my GCP Firestore database. I found out that Firestore has Import/ Export functionality, and it seems to be the recommended way to do backup. So I created a simple GitHub Actions workflow to do this:

name: Firestore backup

on:
  workflow_dispatch:
  schedule:
    - cron: "0 19 * * *"

jobs:
  backup:
    runs-on: ubuntu-latest

    steps:
      - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
        with:
          service_account_email: '<service-account-name>@<project-id>.iam.gserviceaccount.com'
          service_account_key: ${{ secrets.SA_KEY }}
          project_id: '<project-id>'

      - name: Backup
        run: |-
          gcloud components install beta
          gcloud beta firestore export gs://<storage-bucket-id>


This workflow can be triggered in 2 ways, manually (due to workflow_dispatch trigger), or on a schedule (cron syntax).

The first step set up and authenticate the gcloud cli. The second step triggers to export action on GCP.
Currently firestore export is only available on gcloud beta, so an installation step of the beta component is needed.

The cloud storage bucket would need to be created beforehand. I created mine with the NEARLINE storage class to save on some cost.

comments powered by Disqus