Skip to content

Instantly share code, notes, and snippets.

@DennisAlund
Created April 25, 2020 14:20
Show Gist options
  • Save DennisAlund/da799bba6eacbf0ffeb968c8bdaa760d to your computer and use it in GitHub Desktop.
Save DennisAlund/da799bba6eacbf0ffeb968c8bdaa760d to your computer and use it in GitHub Desktop.
name: Backup archive
env:
BACKUP_BUCKET: "gs://example-prod-backups"
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
on:
schedule:
# First of every month at some time when your app is least active
- cron: "0 3 1 * *"
jobs:
backup-firestore:
runs-on: ubuntu-latest
steps:
- name: Setup gcloud environment
uses: GoogleCloudPlatform/github-actions@0.1.2
with:
project_id: example-prod
service_account_key: ${{ secrets.GCLOUD_AUTH_KEY_PROD }}
- name: Select project
run: gcloud config set project example-prod
- name: Export Firestore
run: gcloud firestore export ${{ env.BACKUP_BUCKET }}/firestore/$(date '+%Y-%m-%d') --async
backup-rtdb:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup gcloud environment
uses: GoogleCloudPlatform/github-actions@0.1.2
with:
project_id: example-prod
service_account_key: ${{ secrets.GCLOUD_AUTH_KEY_PROD }}
- name: Select project
run: gcloud config set project example-prod
- name: Select Firebase project
uses: w9jds/firebase-action@v1.3.0
with:
args: use production
- name: Generate backup file name
run: |
echo "::set-env name=BACKUP_FILE::$(date '+%Y-%m-%d').json"
- name: Download RTDB data
uses: w9jds/firebase-action@v1.3.0
with:
args: database:get --output ${{ env.BACKUP_FILE }} /
- name: Upload to Cloud Storage Bucket
run: gsutil cp ${{ env.BACKUP_FILE }} ${{ env.BACKUP_BUCKET }}/rtdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment