Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Last active June 4, 2024 02:03
Show Gist options
  • Save PaulieScanlon/d3c9c993b5e2b76bc8b44fb91e324442 to your computer and use it in GitHub Desktop.
Save PaulieScanlon/d3c9c993b5e2b76bc8b44fb91e324442 to your computer and use it in GitHub Desktop.
Finished GitHub Action
name: Backup Neon | paulie-dev (us-east-1)
on:
schedule:
# Runs at midnight ET (us-east-1)
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
db-backup:
runs-on: ubuntu-latest
permissions:
id-token: write
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
PG_VERSION: '16'
AWS_REGION: 'us-east-1'
S3_BUCKET_URL: ${{ secrets.S3_BUCKET_URL }}
steps:
- name: Install PostgreSQL
run: |
sudo apt install -y postgresql-common
yes '' | sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt install -y postgresql-${{ env.PG_VERSION }}
- name: Get timestamp
id: timestamp
run: |
echo "TIMESTAMP=$(date +%d-%B-%Y@%H:%M:%S)" >> $GITHUB_ENV
- name: Run pg_dump
run: |
TIMESTAMP="${{ env.TIMESTAMP }}"
/usr/lib/postgresql/${{ env.PG_VERSION }}/bin/pg_dump ${{ env.DATABASE_URL}} | gzip > "${TIMESTAMP}.sql.gz"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/paulie-dev-2023-github-action
aws-region: ${{ env.AWS_REGION }}
- name: Empty Bucket
run: |
aws s3 rm ${{ env.S3_BUCKET_URL }} --recursive
- name: Upload to Bucket
run: |
TIMESTAMP="${{ env.TIMESTAMP }}"
aws s3 cp "${TIMESTAMP}.sql.gz" ${{ env.S3_BUCKET_URL }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment