Back to Config Library
GitHub Action
v1.0.0

Postgres DB Backup Workflow

GitHub Action that backs up your PostgreSQL database weekly and stores it as a GitHub artifact.

Files Included

33 linesEnter email to access
name: Postgres DB Backup

on:
  schedule:
    # Every Sunday at 6am UTC
    - cron: '0 6 * * 0'
  workflow_dispatch:

jobs:
  backup:
    runs-on: ubuntu-latest
    steps:
      - name: Install PostgreSQL client
        run: sudo apt-get update && sudo apt-get install -y postgresql-client

      - name: Create backup
        env:
          DIRECT_URL: ${{ secrets.DIRECT_URL }}
        run: |
          TIMESTAMP=$(date +%Y%m%d_%H%M%S)
          pg_dump "$DIRECT_URL" \
            --format=custom \
            --no-owner \
            --no-privileges \
            --file="backup_${TIMESTAMP}.dump"
          echo "BACKUP_FILE=backup_${TIMESTAMP}.dump" >> $GITHUB_ENV

      - name: Upload backup artifact
        uses: actions/upload-artifact@v4
        with:
          name: db-backup-${{ github.run_id }}
          path: ${{ env.BACKUP_FILE }}
          retention-days: 90

How to use

Copy to .github/workflows/db-backup.yml in your repo. Add a DIRECT_URL secret with your Postgres connection string. Runs automatically every Sunday at 6am UTC.

About

A scheduled GitHub Actions workflow that runs pg_dump against your PostgreSQL database every Sunday at 6am UTC. Saves the backup as a custom-format dump file, uploads it as a GitHub artifact with 90-day retention. Can also be triggered manually. Uses DIRECT_URL secret for the connection string.

PostgreSQLBackupCI/CDFree
Free

Get notified about new configs. No spam.

What’s Included

  • Weekly scheduled backups (cron)
  • Manual trigger option
  • pg_dump custom format
  • 90-day artifact retention
  • Works with any Postgres (Supabase, Neon, etc.)
  • Single secret setup (DIRECT_URL)

1 file included

    Postgres DB Backup Workflow | Starmorph Config | Starmorph