Database Backup #64
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: Database Backup | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| db-service: | |
| description: "cloud.gov database service name" | |
| required: false | |
| type: string | |
| default: nrrd-a-psql | |
| cf-space: | |
| description: "cloud.gov space" | |
| required: false | |
| type: string | |
| default: prod | |
| schedule: | |
| - cron: '0 3 * * 0,4' # runs on Sunday and Thursday at 3am UTC | |
| env: | |
| DB_SERVICE: ${{ inputs.db-service || 'nrrd-a-psql' }} | |
| CF_SPACE: ${{ inputs.cf-space || 'prod' }} | |
| jobs: | |
| db-backup: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install PostgreSQL client | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y postgresql-client | |
| - name: Verify pg_dump version | |
| run: pg_dump --version | |
| - name: Install CF CLI | |
| uses: doi-onrr/oddd-actions/.github/actions/cf-install@v1 | |
| - name: Install cg-manage-rds (pipx) | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y python3 python3-pip pipx | |
| pipx ensurepath | |
| pipx install git+https://github.com/cloud-gov/cg-manage-rds.git | |
| cg-manage-rds --help | |
| - name: Log in to Cloud Foundry | |
| shell: bash | |
| run: | | |
| cf login -u ${{ secrets.CF_USERNAME }} -p ${{ secrets.CF_PASSWORD }} -a api.fr.cloud.gov -o doi-onrr -s "$CF_SPACE" | |
| - name: Backup database | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 30 | |
| max_attempts: 3 | |
| retry_wait_seconds: 30 | |
| shell: bash | |
| command: | | |
| set -eo pipefail | |
| cd "${{ github.workspace }}" | |
| rm -f backup.sql | |
| cg-manage-rds export -o "-F p --no-owner --no-acl" -f backup.sql "$DB_SERVICE" 2>&1 | |
| test -s backup.sql | |
| ls -lh backup.sql | |
| - name: Compress backup | |
| run: | | |
| gzip -9 backup.sql | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: db-backup-${{ env.CF_SPACE }}-${{ env.DB_SERVICE }} | |
| path: | | |
| backup.sql.gz | |
| retention-days: 14 |