-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2031] Workflows for database backup/restore (#1519)
- Loading branch information
Showing
5 changed files
with
226 additions
and
57 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Restore database from point in time to new database server | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
description: Environment to restore | ||
required: true | ||
default: test | ||
type: choice | ||
options: | ||
- test | ||
- production | ||
confirm-production: | ||
description: Must be set to true if restoring production | ||
required: true | ||
default: 'false' | ||
type: choice | ||
options: | ||
- 'false' | ||
- 'true' | ||
restore-time: | ||
description: Restore point in time in UTC. e.g. 2024-07-24T06:00:00 | ||
type: string | ||
required: true | ||
|
||
env: | ||
SERVICE_SHORT: trs | ||
TF_VARS_PATH: terraform/aks/config | ||
|
||
jobs: | ||
ptr-restore: | ||
name: PTR Restore AKS Database | ||
if: ${{ inputs.environment != 'production' || (inputs.environment == 'production' && github.event.inputs.confirm-production == 'true' ) }} | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.environment }} | ||
concurrency: deploy_${{ inputs.environment }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set environment variables | ||
run: | | ||
source global_config/${{ inputs.environment }}.sh | ||
tf_vars_file=${TF_VARS_PATH}/${{ inputs.environment }}.tfvars.json | ||
echo "CLUSTER=$(jq -r '.cluster' ${tf_vars_file})" >> $GITHUB_ENV | ||
echo "RESOURCE_GROUP_NAME=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-rg" >> $GITHUB_ENV | ||
echo "DB_SERVER=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-pg" >> $GITHUB_ENV | ||
- name: Restore ${{ inputs.environment }} postgres | ||
uses: DFE-Digital/github-actions/ptr-postgres@master | ||
with: | ||
resource-group: ${{ env.RESOURCE_GROUP_NAME }} | ||
source-server: ${{ env.DB_SERVER }} | ||
new-server: ${{ env.DB_SERVER }}-ptr | ||
restore-time: ${{ inputs.restore-time }} | ||
cluster: ${{ env.CLUSTER }} | ||
azure-credentials: ${{ secrets.AZURE_CREDENTIALS}} | ||
|
||
- name: Restore Summary | ||
if: success() | ||
run: | | ||
NOW=$(TZ=Europe/London date +"%F %R") | ||
echo 'RESTORE SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY | ||
echo ' ENV: ${{ inputs.environment }}' >> $GITHUB_STEP_SUMMARY | ||
echo " AT : ${NOW}" >> $GITHUB_STEP_SUMMARY | ||
echo ' SOURCE SERVER: ${{ env.DB_SERVER }}' >> $GITHUB_STEP_SUMMARY | ||
echo ' RESTORED SERVER: ${{ env.DB_SERVER }}-ptr' >> $GITHUB_STEP_SUMMARY | ||
echo ' RESTORE POINT: ${{ inputs.restore-time }} UTC' >> $GITHUB_STEP_SUMMARY |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Restore database from Azure storage | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
description: Environment to restore | ||
required: true | ||
default: test | ||
type: choice | ||
options: | ||
- test | ||
# - production | ||
confirm-production: | ||
description: Must be set to true if restoring production | ||
required: true | ||
default: 'false' | ||
type: choice | ||
options: | ||
- 'false' | ||
- 'true' | ||
backup-file: | ||
description: Name of the backup file in Azure storage. e.g. trs_prod_2024-08-09.tar.gz. The default value is today's scheduled backup. | ||
type: string | ||
required: false | ||
|
||
env: | ||
SERVICE_NAME: trs | ||
SERVICE_SHORT: trs | ||
TF_VARS_PATH: terraform/aks/config | ||
|
||
jobs: | ||
restore: | ||
name: Restore AKS Database | ||
if: ${{ inputs.environment != 'production' || (inputs.environment == 'production' && github.event.inputs.confirm-production == 'true' ) }} | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.environment }} | ||
concurrency: deploy_${{ inputs.environment }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
name: Checkout | ||
|
||
- name: Set environment variables | ||
run: | | ||
source global_config/${{ inputs.environment }}.sh | ||
tf_vars_file=${{ env.TF_VARS_PATH }}/${{ inputs.environment }}.tfvars.json | ||
echo "CLUSTER=$(jq -r '.cluster' ${tf_vars_file})" >> $GITHUB_ENV | ||
echo "RESOURCE_GROUP_NAME=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-rg" >> $GITHUB_ENV | ||
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 | ||
TODAY=$(date +"%F") | ||
echo "BACKUP_FILE=${SERVICE_SHORT}_${CONFIG_SHORT}_${TODAY}.sql" >> $GITHUB_ENV | ||
if [ "${{ inputs.backup-file }}" != "" ]; then | ||
BACKUP_FILE=${{ inputs.backup-file }} | ||
else | ||
BACKUP_FILE=${SERVICE_SHORT}_${CONFIG_SHORT}_${TODAY}.sql.gz | ||
fi | ||
echo "BACKUP_FILE=$BACKUP_FILE" >> $GITHUB_ENV | ||
- name: Restore ${{ inputs.environment }} postgres | ||
uses: DFE-Digital/github-actions/restore-postgres-backup@master | ||
with: | ||
storage-account: ${{ env.STORAGE_ACCOUNT_NAME }} | ||
resource-group: ${{ env.RESOURCE_GROUP_NAME }} | ||
app-name: ${{ env.SERVICE_NAME }}-${{ inputs.environment }}-api | ||
cluster: ${{ env.CLUSTER }} | ||
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }} | ||
backup-file: ${{ env.BACKUP_FILE }} | ||
|
||
- name: Restore Summary | ||
if: success() | ||
run: | | ||
NOW=$(TZ=Europe/London date +"%F %R") | ||
echo 'RESTORE SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY | ||
echo ' ENV: ${{ inputs.environment }}' >> $GITHUB_STEP_SUMMARY | ||
echo " AT : ${NOW}" >> $GITHUB_STEP_SUMMARY | ||
echo ' DB SERVER: ${{ env.DB_SERVER }}' >> $GITHUB_STEP_SUMMARY | ||
echo ' BACKUP FILE RESTORED: ${{ env.BACKUP_FILE }}' >> $GITHUB_STEP_SUMMARY |