-
-
Save bogordesaincom/83ac26f1e2ef5a6c885b97db87a81db1 to your computer and use it in GitHub Desktop.
Back up a Fly.io Postgres database to S3 using GitHub Actions
This file contains 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/s3cmd@v1.2.0 | |
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