Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Db backup restore #877

Closed
wants to merge 10 commits into from
40 changes: 40 additions & 0 deletions .github/workflows/backup-db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Supa-backup

on:
push:
branches: [ development ]
pull_request:
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved
branches: [ development ]
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
run_db_backup:
runs-on: ubuntu-latest
permissions:
contents: write
env:
supabase_db_url: ${{ secrets.SUPABASE_DB_URL }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved

- uses: supabase/setup-cli@v1
with:
version: latest

- name: Generate timestamp
id: timestamp
run: echo "::set-output name=timestamp::$(date +'%Y%m%d%H%M%S')"

- name: Backup schema
run: supabase db dump --db-url "$supabase_db_url" -f ${{ steps.timestamp.outputs.timestamp }}_schema.sql

- name: Backup data
run: supabase db dump --db-url "$supabase_db_url" -f ${{ steps.timestamp.outputs.timestamp }}_data.sql --data-only --use-copy

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Supabase backup
34 changes: 34 additions & 0 deletions .github/workflows/restore-db
Keyrxng marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Supa-restore

on:
push:
branches: [ restore ]
workflow_dispatch:

jobs:
run_db_restore:
runs-on: ubuntu-latest
permissions:
contents: write

env:
supabase_db_url: ${{ secrets.SUPABASE_RESTORE_DB_URL }}

steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- uses: supabase/setup-cli@v1
with:
version: latest

- name: Install PostgreSQL client
run: sudo apt-get install -y postgresql-client

- name: Restore database dump to Supabase
run: |
PGPASSWORD=${{ secrets.SUPABASE_DB_PASSWORD }} psql -h ${{ secrets.SUPABASE_DB_URL }} -p ${{ secrets.SUPABASE_PORT }} -d ${{ secrets.SUPABASE_NAME }} -U ${{ secrets.SUPABASE_USER }} < schema.sql
PGPASSWORD=${{ secrets.SUPABASE_DB_PASSWORD }} psql -h ${{ secrets.SUPABASE_DB_URL }} -p ${{ secrets.SUPABASE_PORT }} -d ${{ secrets.SUPABASE_NAME }} -U ${{ secrets.SUPABASE_USER }} < data.sql
env:
SUPABASE_DB_PASSWORD: ${{ secrets.SUPABASE_DB_PASSWORD }}
Loading