Skip to content

Backup Neon | paulie-dev (us-east-1) #267

Backup Neon | paulie-dev (us-east-1)

Backup Neon | paulie-dev (us-east-1) #267

Workflow file for this run

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:
BACKUP_ID: 'paulie.dev'
DATABASE_URL: ${{ secrets.DATABASE_URL }}
PG_VERSION: '16'
AWS_REGION: 'us-east-1'
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
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 }}"
FILENAME="${{ env.BACKUP_ID }}-${TIMESTAMP}.sql.gz"
/usr/lib/postgresql/${{ env.PG_VERSION }}/bin/pg_dump ${{ env.DATABASE_URL}} | gzip > "${FILENAME}"
echo "FILENAME=${FILENAME}" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.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: |
FILENAME="${{ env.FILENAME }}"
aws s3 cp "${FILENAME}" ${{ env.S3_BUCKET_URL }}