Created
January 21, 2023 16:35
-
-
Save mfilej/af354f315508f114259773cc17c8d964 to your computer and use it in GitHub Desktop.
Back up a Fly.io Postgres database to S3 using GitHub Actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Back up database | |
run-name: Task | |
on: | |
schedule: | |
- cron: '0 4 * * *' | |
workflow_dispatch: | |
jobs: | |
backup: | |
runs-on: ubuntu-latest | |
env: | |
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} | |
PGUSER: postgres | |
PGPASSWORD: ${{ secrets.PGPASSWORD }} | |
PGDATABASE: your_database_name | |
PGHOST: localhost | |
PGPORT: 5555 | |
steps: | |
- uses: s3-actions/[email protected] | |
with: | |
provider: aws | |
region: eu-central-1 | |
access_key: ${{ secrets.S3_ACCESS_KEY }} | |
secret_key: ${{ secrets.S3_SECRET_KEY }} | |
- uses: superfly/flyctl-actions/setup-flyctl@master | |
- name: Set filename | |
run: echo "filename=db-$(date -u +"%Y-%m-%d-%H%M%S").dump" >> $GITHUB_ENV | |
- name: Dump database and upload to S3 | |
run: | | |
flyctl proxy 5555:5432 -a your-fly-db-app-name & | |
sleep 3 | |
echo Dumping ... | |
pg_dump -Fc -f ${{ env.filename }} | |
ls | |
s3cmd put --acl-private ${{ env.filename }} s3://your-s3-bucket/your-path/${{ env.filename }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment