Skip to content

Oracle: delius-core-dev_daily_delius_primarydb_database_backup #31

Oracle: delius-core-dev_daily_delius_primarydb_database_backup

Oracle: delius-core-dev_daily_delius_primarydb_database_backup #31

name: "Oracle: Backup"
run-name: "Oracle: ${{ github.event_name == 'workflow_dispatch' && format('{0}_{1}_{2}', github.event.inputs.TargetEnvironment, github.event.inputs.Period, github.event.inputs.TargetHost) }}_database_backup"
on:
workflow_dispatch:
inputs:
TargetEnvironment:
description: "Target environment"
required: true
type: choice
options:
- "delius-core-dev"
- "delius-core-test"
- "delius-core-training"
- "delius-core-stage"
- "delius-core-pre-prod"
- "delius-core-prod"
TargetHost:
description: "Backup target host"
required: true
type: choice
options:
- "delius_primarydb"
- "mis_primarydb"
- "misboe_primarydb"
- "misdsd_primarydb"
- "delius_standbydb1"
- "mis_standbydb1"
- "misboe_standbydb1"
- "misdsd_standbydb1"
- "delius_standbydb2"
TargetHostList:
description: "INTERNAL USE ONLY"
type: string
default: "delius_primarydb, mis_primarydb, misboe_primarydb, misdsd_primarydb, delius_standbydb1, mis_standbydb1,misboe_standbydb1,misdsd_standbydb1,delius_standbydb2"
Period:
description: "Is this a daily or weekly backup?"
required: true
type: choice
options:
- "daily"
- "weekly"
FixAbsentChunks:
description: "Validate and fix absent S3 missing backup chunks"
type: choice
default: "yes"
options:
- "yes"
- "no"
DeleteDefunct:
description: "Delete backups for DBIDs no longer in use"
type: choice
default: "no"
options:
- "yes"
- "no"
EnableTrace:
description: "Enable RMAN trace for debugging"
required: false
type: choice
default: "no"
options:
- "yes"
- "no"
VerboseOutput:
description: "Verbose Output level"
type: choice
options:
- ""
- "-v"
- "-vv"
- "-vvv"
- "-vvvv"
SourceCodeVersion:
description: "Source version for the hmpps-delius-operation-automation. Enter a pull request, branch, commit ID, tag, or reference."
type: string
default: "main"
SourceConfigVersion:
description: "Source version for the modernisation-platform-configuration-management. Enter a pull request, branch, commit ID, tag, or reference."
type: string
default: "main"
workflow_call:
inputs:
TargetEnvironment:
description: "Target environment"
required: true
type: string
TargetHost:
description: "Backup target host"
required: true
type: string
Period:
description: "Is this a daily or weekly backup?"
required: true
type: string
DeleteDefunct:
description: "Delete backups for DBIDs no longer in use"
required: false
type: string
default: "no"
# Allow permissions on repository and docker image and OIDC token
permissions:
contents: read
packages: read
id-token: write # This is required for requesting the JWT
jobs:
build_rman_target_name:
runs-on: ubuntu-latest
outputs:
RmanTarget: ${{ steps.preparermantargetname.outputs.RmanTarget }}
TargetEnvironment: ${{ steps.preparermantargetname.outputs.TargetEnvironment }}
steps:
- name: Prepare Rman Target
id: preparermantargetname
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]
then
TargetHost="${{ github.event.inputs.TargetHost }}"
TargetEnvironment="${{ github.event.inputs.TargetEnvironment }}"
elif [[ "${{ github.event_name }}" == "schedule" ]]
then
TargetHost="${{ inputs.TargetHost }}"
TargetEnvironment="${{ inputs.TargetEnvironment }}"
fi;
RmanTarget="environment_name_$(echo $TargetEnvironment | sed 's/delius-core-dev/delius_core_development_dev/;s/delius-core-test/delius_core_test_test/;s/delius-core-training/delius_core_test_training/;s/delius-core-stage/delius_core_preproduction_stage/;s/delius-core-pre-prod/delius_core_preproduction_pre_prod/;s/delius-core-prod/delius_core_production_prod/')_$TargetHost"
echo "RmanTarget=$RmanTarget" >> $GITHUB_OUTPUT
echo "TargetEnvironment=$TargetEnvironment" >> $GITHUB_OUTPUT
# Start deployment container job based on the build delius-ansible-aws image
deployment:
name: oracle-backup
needs: build_rman_target_name
environment: ${{needs.build_rman_target_name.outputs.TargetEnvironment}}
runs-on: ubuntu-latest
container:
image: ghcr.io/ministryofjustice/hmpps-delius-operational-automation:0.1
timeout-minutes: 1440
env:
backup_command: ansible-playbook operations/playbooks/oracle_backup/backup.yml
validate_command: ansible-playbook operations/playbooks/oracle_backup/validate.yml
delete_dbids_command: ansible-playbook operations/playbooks/oracle_backup/delete_dbids_not_in_use.yml
inventory: inventory/ansible
Period: "${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.Period || (github.event_name == 'schedule' && inputs.Period )) }}"
FixAbsentChunks: "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.FixAbsentChunks || 'yes' }}"
DeleteDefunct: "${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.DeleteDefunct || (github.event_name == 'schedule' && inputs.DeleteDefunct )) }}"
EnableTrace: "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.EnableTrace || 'no' }}"
VerboseOutput: "${{ github.event_name == 'workflow_dispatch' && github.event.inputs.VerboseOutput || '' }}"
RmanTarget: "${{needs.build_rman_target_name.outputs.RmanTarget}}"
continue-on-error: false
steps:
- name: Checkout hmpps-delius-operation-automation
uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
playbooks/oracle_backup
path: operations
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.SourceCodeVersion || 'main' }}
fetch-depth: 0
- name: Checkout modernisation-platform-configuration-management
uses: actions/checkout@v4
with:
repository: ministryofjustice/modernisation-platform-configuration-management
sparse-checkout-cone-mode: false
sparse-checkout: |
ansible/hosts
ansible/group_vars
path: inventory
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.SourceConfigVersion || 'main' }}
fetch-depth: 0
- name: Configure AWS Credentials
id: login-aws
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: "arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/modernisation-platform-oidc-cicd"
role-session-name: "hmpps-delius-operational-automation-${{ github.run_number }}"
aws-region: "eu-west-2"
- name: Start Ansible Backup
run: $backup_command -i $inventory -e rman_target=$RmanTarget -e daily_weekly=$Period -e enable_trace=$EnableTrace $VerboseOutput
- name: Start Ansible Validate And Fix Absent Chunks
run: $validate_command -i $inventory -e rman_target=$RmanTarget -e fix_absent_chunks=$FixAbsentChunks $VerboseOutput
- name: Start Ansible Delete DBIDs Not In Use
if: ${{ env.DeleteDefunct == 'yes' }}
run: $delete_dbids_command -i $inventory -e rman_target=$RmanTarget $VerboseOutput