diff --git a/.github/workflows/schedule-db-backup.yml b/.github/workflows/schedule-db-backup.yml new file mode 100644 index 000000000..56c26f694 --- /dev/null +++ b/.github/workflows/schedule-db-backup.yml @@ -0,0 +1,22 @@ +name: Schedule Database Backup + +on: + schedule: + - cron: '0 0 * * *' # Runs every night at midnight UTC + workflow_dispatch: + +jobs: + backup-test: + uses: ./.github/workflows/templates/db-backup.yml + with: + runner: tst + + backup-acceptance: + uses: ./.github/workflows/db-backup.yml + with: + runner: ACC + + backup-production: + uses: ./.github/workflows/db-backup.yml + with: + runner: PRD \ No newline at end of file diff --git a/.github/workflows/templates/db-backup.yml b/.github/workflows/templates/db-backup.yml new file mode 100644 index 000000000..c3b57df90 --- /dev/null +++ b/.github/workflows/templates/db-backup.yml @@ -0,0 +1,25 @@ +name: Database Backup Template + +on: + workflow_call: + inputs: + runner: + required: true + type: string + +jobs: + backup: + runs-on: ${{ inputs.runner }} + steps: + + - name: Set Date + id: date + run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV + + - name: Backup Database + run: | + podman exec muscle_db_1 sh -c "pg_dump -Fc > /backups/${{ env.DATE }}.dump" + + - name: Remove Old Backups (older than 7 days) + run: | + podman exec muscle_db_1 sh -c "find /backups -type f -name '*.dump' -mtime +7 -exec rm {} \;" \ No newline at end of file