Skip to content

Instantly share code, notes, and snippets.

@mansueli
Created September 7, 2023 14:55
Show Gist options
  • Save mansueli/e9dc3b6ca562c35fa58f4e37348cc452 to your computer and use it in GitHub Desktop.
Save mansueli/e9dc3b6ca562c35fa58f4e37348cc452 to your computer and use it in GitHub Desktop.
Commit backup - workflow
# This is a basic workflow to help you get started with Actions
name: Supa-backup
# Controls when the workflow will run
on:
# Allows you to run this workflow manually from the Actions tab
push:
branches: [ main ]
pull_request:
branches: [main]
workflow_dispatch:
schedule:
- cron: '0 */6 * * *'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
run_db_backup:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
contents: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Postgres15
run: |
sudo apt-get remove postgresql-client-common
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
sudo apt update
sudo apt install postgresql-15 postgresql-client-15 -y
/usr/lib/postgresql/15/bin/pg_dump --clean --if-exists --quote-all-identifiers --schema '*' --exclude-schema 'extensions|graphql|graphql_public|net|pgbouncer|pgsodium|pgsodium_masks|realtime|supabase_functions|storage|pg_*|information_schema' -d postgres://postgres:${{ secrets.SUPABASE_PASSWORD }}@${{ secrets.SUPABASE_URL }}:6543/postgres > dump.sql
- name: Tweaking the dump file
run: |
sed -i -e 's/^DROP SCHEMA IF EXISTS "auth";$/-- DROP SCHEMA IF EXISTS "auth";/' dump.sql
sed -i -e 's/^DROP SCHEMA IF EXISTS "storage";$/-- DROP SCHEMA IF EXISTS "storage";/' dump.sql
sed -i -e 's/^CREATE SCHEMA "auth";$/-- CREATE SCHEMA "auth";/' dump.sql
sed -i -e 's/^CREATE SCHEMA "storage";$/-- CREATE SCHEMA "storage";/' dump.sql
sed -i -e 's/^ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin"/-- ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin"/' dump.sql
shell: bash
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Supabase backup
- name: Commit results
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git add .
git commit -m 'Supabase backup "$d"' || echo "No changes to commit"
git push origin || echo "No changes to commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment