-
Notifications
You must be signed in to change notification settings - Fork 1
72 lines (66 loc) · 2.66 KB
/
database-restore.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Restore database from Azure storage
on:
workflow_dispatch:
inputs:
environment:
description: Environment to restore
required: true
default: development
type: choice
options:
- development
- test
- preprod
- 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. afqts_prod_2024-08-09.sql.gz. The default value is today's scheduled backup.
type: string
required: false
env:
SERVICE_NAME: apply-for-qts
SERVICE_SHORT: afqts
TF_VARS_PATH: terraform/application/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 }}/${CONFIG}/variables.tfvars.json
echo "CONFIG=${CONFIG}" >> $GITHUB_ENV
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 }}-${CONFIG}-web
cluster: ${{ env.CLUSTER }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
backup-file: ${{ env.BACKUP_FILE }}