diff --git a/.github/actions/backup-and-restore-snapshot-database/action.yml b/.github/actions/directly-backup-and-restore-snapshot-database/action.yml similarity index 68% rename from .github/actions/backup-and-restore-snapshot-database/action.yml rename to .github/actions/directly-backup-and-restore-snapshot-database/action.yml index a9b08f17..0ba01cdb 100644 --- a/.github/actions/backup-and-restore-snapshot-database/action.yml +++ b/.github/actions/directly-backup-and-restore-snapshot-database/action.yml @@ -1,5 +1,5 @@ -name: Backup production and restore snapshot DB -description: Dump production DB and straight restore to snapshot DB keeping no copy in Azure Storage +name: Directly backup main db of an environment and restore snapshot db +description: Dump main db of an environment and directly restore to snapshot db bypassing Azure Storage inputs: environment: @@ -33,7 +33,7 @@ runs: - name: Set AKS credentials shell: bash - run: make ci production get-cluster-credentials + run: make ci ${{ inputs.environment }} get-cluster-credentials - name: Install kubectl uses: DFE-Digital/github-actions/set-kubectl@master @@ -56,7 +56,7 @@ runs: shell: bash run: | NOW=$(TZ=Europe/London date +"%F %R") - echo 'STRAIGHT COPY OF PRODUCTION-SNAPSHOT DB SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY + echo 'DIRECT COPY OF ${{ inputs.environment }}->SNAPSHOT DB SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY echo ' APP: ${{ inputs.app-name }}' >> $GITHUB_STEP_SUMMARY echo " AT : ${NOW}" >> $GITHUB_STEP_SUMMARY @@ -65,19 +65,19 @@ runs: uses: rtCamp/action-slack-notify@v2 env: SLACK_USERNAME: CI Deployment - SLACK_TITLE: Nightly copy production-snapshot database succeeded - SLACK_MESSAGE: ${{ inputs.app-name }} - the straight copy of production-snapshot db succeeded + SLACK_TITLE: Direct copy ${{ inputs.environment }}->snapshot database succeeded + SLACK_MESSAGE: ${{ inputs.app-name }} - the direct copy of ${{ inputs.environment }}->snapshot db succeeded SLACK_WEBHOOK: ${{ inputs.slack-webhook }} SLACK_COLOR: success - SLACK_FOOTER: Sent from backup-and-restore-snapshot-database action + SLACK_FOOTER: Sent from directly-backup-and-restore-snapshot-database action - name: Notify Slack channel on job failure if: failure() uses: rtCamp/action-slack-notify@v2 env: SLACK_USERNAME: CI Deployment - SLACK_TITLE: Nightly backup production and straight restore of Snapshot database failed - SLACK_MESSAGE: ${{ inputs.app-name }} - the straight copy of production-snapshot db failed + SLACK_TITLE: Direct copy ${{ inputs.environment }}->snapshot database failed + SLACK_MESSAGE: ${{ inputs.app-name }} - the direct copy of ${{ inputs.environment }}->snapshot db failed SLACK_WEBHOOK: ${{ inputs.slack-webhook }} - SLACK_COLOR: failure - SLACK_FOOTER: Sent from backup-and-restore-snapshot-database action + SLACK_COLOR: failures + SLACK_FOOTER: Sent from directly-backup-and-restore-snapshot-database action diff --git a/.github/workflows/backup-db.yml b/.github/workflows/backup-db.yml index 582c2adf..00a64115 100644 --- a/.github/workflows/backup-db.yml +++ b/.github/workflows/backup-db.yml @@ -86,6 +86,7 @@ jobs: echo "STORAGE_ACCOUNT_NAME=${AZURE_RESOURCE_PREFIX}${SERVICE_SHORT}dbbkp${CONFIG_SHORT}sa" >> $GITHUB_ENV echo "DB_SERVER=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-pg" >> $GITHUB_ENV echo "KEYVAULT_NAME=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-inf-kv" >> $GITHUB_ENV + echo "APP_NAME=${SERVICE_NAME}-${DEPLOY_ENV}-web" >> $GITHUB_ENV - name: Generate the backup file name run: | @@ -117,9 +118,20 @@ jobs: with: storage-account: ${{ env.STORAGE_ACCOUNT_NAME }} resource-group: ${{ env.RESOURCE_GROUP_NAME }} - app-name: ${{ env.SERVICE_NAME }}-${{ env.DEPLOY_ENV }}-web + app-name: ${{ env.APP_NAME }} cluster: ${{ env.CLUSTER }} azure-credentials: ${{ secrets.azure-credentials || secrets.AZURE_CREDENTIALS }} backup-file: ${{ env.BACKUP_FILE }}.sql db-server-name: ${{ inputs.db-server }} slack-webhook: ${{ steps.key-vault-secrets.outputs.SLACK_WEBHOOK }} + + - name: Notify Slack channel on job success + if: success() + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_USERNAME: CI Deployment + SLACK_TITLE: ${{ env.DEPLOY_ENV }} database dump stored in Azure Storage (${{ env.STORAGE_ACCOUNT_NAME }}) - Success + SLACK_MESSAGE: ${{ env.APP_NAME }} - ${{ env.DEPLOY_ENV }} database backup job succeeded + SLACK_WEBHOOK: ${{ steps.key-vault-secrets.outputs.SLACK_WEBHOOK }} + SLACK_COLOR: success + SLACK_FOOTER: Sent from backup-db workflow diff --git a/.github/workflows/nightly_copy_production_db_straight_into_snapshot_db.yml b/.github/workflows/directly-copy-main-db-into-snapshot-db.yml similarity index 84% rename from .github/workflows/nightly_copy_production_db_straight_into_snapshot_db.yml rename to .github/workflows/directly-copy-main-db-into-snapshot-db.yml index 0a8891af..e3f5a2a2 100644 --- a/.github/workflows/nightly_copy_production_db_straight_into_snapshot_db.yml +++ b/.github/workflows/directly-copy-main-db-into-snapshot-db.yml @@ -1,10 +1,10 @@ -name: Nightly copy production main db into snapshot db keeping no backup in Azure Storage +name: Directly copy an env main db into to the snapshot db, bypassing Azure Storage on: workflow_dispatch: inputs: environment: - description: GitHub environment to backup and restore + description: GitHub environment to backup type: choice default: production options: @@ -12,16 +12,13 @@ on: - production required: true - schedule: - - cron: "45 3 * * *" # 03:45 UTC - env: SERVICE_NAME: cpd-ec2 SERVICE_SHORT: cpdec2 TF_VARS_PATH: config/terraform/application/config jobs: - backup-production-and-restore-snapshot: + backup-main-db-and-restore-snapshot: runs-on: ubuntu-latest environment: name: ${{ inputs.environment || 'production' }} @@ -55,7 +52,7 @@ jobs: echo "SLACK_WEBHOOK=$SLACK_WEBHOOK" >> $GITHUB_OUTPUT - name: Backup and restore snapshot - uses: ./.github/actions/backup-and-restore-snapshot-database + uses: ./.github/actions/directly-backup-and-restore-snapshot-database with: environment: ${{ inputs.environment || 'production' }} azure-credentials: ${{ secrets.AZURE_CREDENTIALS }} diff --git a/.github/workflows/nightly-backup-of-production-db.yml b/.github/workflows/nightly-backup-of-production-db.yml deleted file mode 100644 index 724d2f5d..00000000 --- a/.github/workflows/nightly-backup-of-production-db.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Nightly backup production database and upload it to Azure Storage - -on: - schedule: - - cron: "15 0 * * *" # 00:15 UTC - -jobs: - backup-production-and-store-in-azure-storage: - runs-on: ubuntu-latest - uses: ./.github/workflows/backup-db.yml - with: - environment: production diff --git a/.github/workflows/nightly-copy-production_db_into_snapshot_db_and_store_dump.yml b/.github/workflows/nightly-copy-production_db_into_snapshot_db_and_store_dump.yml index 71c377c1..d49b012b 100644 --- a/.github/workflows/nightly-copy-production_db_into_snapshot_db_and_store_dump.yml +++ b/.github/workflows/nightly-copy-production_db_into_snapshot_db_and_store_dump.yml @@ -1,4 +1,4 @@ -name: Nightly copy production main db into snapshot db keeping backup in Azure Storage +name: Nightly copy production main db into the snapshot db keeping backup in Azure Storage on: workflow_dispatch: diff --git a/.github/workflows/restore-app-default-db.yml b/.github/workflows/restore-app-main-db.yml similarity index 98% rename from .github/workflows/restore-app-default-db.yml rename to .github/workflows/restore-app-main-db.yml index 206bb50f..c18d9054 100644 --- a/.github/workflows/restore-app-default-db.yml +++ b/.github/workflows/restore-app-main-db.yml @@ -1,4 +1,4 @@ -name: Restore default app database from Azure storage +name: Restore app main database from Azure storage on: workflow_dispatch: