Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dba 667 #237

Merged
merged 179 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
42b1b10
Get the Backup Status
bill-buchan Mar 21, 2024
90983ba
Add region
bill-buchan Mar 21, 2024
9ca4b38
Wait until credentials available
bill-buchan Mar 21, 2024
b185dac
Rman Target is sufficient
bill-buchan Mar 21, 2024
f4525d0
Handle Unrun status
bill-buchan Mar 21, 2024
c1d0551
Do not fail getting parameter
bill-buchan Mar 21, 2024
4600bb0
Set Status parameter
bill-buchan Mar 21, 2024
5e511c2
Missing keyword
bill-buchan Mar 21, 2024
f6bf465
Use the type
bill-buchan Mar 21, 2024
6737e03
Use bash
bill-buchan Mar 21, 2024
ae8e842
Use String so easier to follow progress
bill-buchan Mar 21, 2024
9a9ed9c
Get the value only
bill-buchan Mar 21, 2024
260702b
Run backup in background
bill-buchan Mar 21, 2024
5344127
Update the SSM Parameter
bill-buchan Mar 21, 2024
3475126
Update comment
bill-buchan Mar 21, 2024
26b07bb
Simplify parameter content
bill-buchan Mar 21, 2024
5e718bf
Update SSM Parameter immediately
bill-buchan Mar 21, 2024
74ff7df
debug
bill-buchan Mar 21, 2024
78ba6f0
Write to log
bill-buchan Mar 21, 2024
d4e8020
AWS Session change should only be for the password function
bill-buchan Mar 21, 2024
b2a1583
Do not reset role used for backups
bill-buchan Mar 21, 2024
06a35f9
Use multiple backup parameters
bill-buchan Mar 21, 2024
4bd510d
Cannot have an empty parameter
bill-buchan Mar 21, 2024
a2befd0
Match variable name
bill-buchan Mar 21, 2024
ecf5519
Name is wrong
bill-buchan Mar 21, 2024
7e74d31
Use JSON for storing Backup runtime
bill-buchan Mar 21, 2024
3b4fe27
Read only SSM Value
bill-buchan Mar 21, 2024
2bd5946
Why not updating?
bill-buchan Mar 21, 2024
007352b
Debug
bill-buchan Mar 21, 2024
0258009
JSON syntax
bill-buchan Mar 21, 2024
71f8ce4
Invert inactive detection
bill-buchan Mar 21, 2024
32d98cb
Comparison syntax
bill-buchan Mar 22, 2024
26b4770
Use Inactive instead of initial
bill-buchan Mar 22, 2024
4cc6bf4
Pass environment variables to jq
bill-buchan Mar 22, 2024
470bee6
Handle duplicate entries in oratab
bill-buchan Mar 22, 2024
d24bd5f
Add Extra Information about the Run
bill-buchan Mar 22, 2024
71a7bbf
Add New Workflow to Validate Chunks
bill-buchan Mar 22, 2024
01b3fd5
Change branch number
bill-buchan Mar 22, 2024
18399c9
Do not run on push
bill-buchan Mar 22, 2024
5bca8ee
Add Backup Marshal
bill-buchan Mar 25, 2024
03323b7
Leave Dispatch
bill-buchan Mar 25, 2024
d6ffbd9
Jobs for All
bill-buchan Mar 25, 2024
a08ff25
Only workflow dispatch
bill-buchan Mar 25, 2024
569af57
Rename steps name
bill-buchan Mar 25, 2024
ad1d836
whitespace
bill-buchan Mar 25, 2024
08d63d4
Remove region
bill-buchan Mar 25, 2024
52c9349
Get AWS Credentials
bill-buchan Mar 25, 2024
ad8ad55
Allow permissions on docker image and OIDC token
bill-buchan Mar 25, 2024
19fbca0
Generate Artifact
bill-buchan Mar 26, 2024
8e63dd9
Remove gibberish
bill-buchan Mar 26, 2024
579b055
List environments
bill-buchan Mar 26, 2024
eeee8f2
Push on branch
bill-buchan Mar 26, 2024
2efc5a5
Full path
bill-buchan Mar 26, 2024
c2e9455
Run through each environment
bill-buchan Mar 26, 2024
08ee7fb
Handle hyphen
bill-buchan Mar 26, 2024
4dd2f24
Why
bill-buchan Mar 26, 2024
a69a67a
Break the lines
bill-buchan Mar 26, 2024
3928c0c
What is wrong
bill-buchan Mar 26, 2024
e734aa6
Do not need value
bill-buchan Mar 26, 2024
004d2a9
Include matrix
bill-buchan Mar 26, 2024
9a60182
Environment matrix
bill-buchan Mar 26, 2024
96ce18a
typo
bill-buchan Mar 26, 2024
6f481b3
Use a strategy list
bill-buchan Mar 26, 2024
d878c71
Merge branch 'main' into DBA-667
bill-buchan Mar 28, 2024
654778a
Allow us to pass JSON to the backup workflow
bill-buchan Mar 28, 2024
c880842
Remove Delete Defunct - run that separately
bill-buchan Mar 28, 2024
114b5dd
Process input JSON
bill-buchan Mar 28, 2024
dd66351
Add Debug
bill-buchan Mar 28, 2024
b665d09
typo
bill-buchan Mar 28, 2024
8de87bb
quoting issue
bill-buchan Mar 28, 2024
3e6791f
Single Quote the JSON
bill-buchan Mar 28, 2024
f7fc4e5
Interim
bill-buchan Mar 28, 2024
02cf824
Fix setting Backup Status with default
bill-buchan Apr 2, 2024
8cb4304
Quotes
bill-buchan Apr 2, 2024
ef38d1f
End Inputs
bill-buchan Apr 2, 2024
8f11ebd
Replace here-doc - code formatter strips out required tabs
bill-buchan Apr 2, 2024
13049d6
Parameterize branches
bill-buchan Apr 2, 2024
80f9841
Prepare Slack Channel Name
bill-buchan Apr 2, 2024
db9acc4
Pass the Backup Status
bill-buchan Apr 2, 2024
bb46682
Use Inputs to pass the Period
bill-buchan Apr 2, 2024
5a1d9c4
Debug
bill-buchan Apr 2, 2024
9387a82
Make naming consistent
bill-buchan Apr 2, 2024
9f46897
Send Repository Dispatch Events
bill-buchan Apr 3, 2024
120c33c
Supply JSON Inputs
bill-buchan Apr 3, 2024
7f0f18f
wrong language!
bill-buchan Apr 3, 2024
3043da8
Cannot overwrite variable
bill-buchan Apr 3, 2024
0ee12e2
Variable name
bill-buchan Apr 3, 2024
e533972
Quote JSON
bill-buchan Apr 3, 2024
ec4d8f0
Wrong quote type
bill-buchan Apr 3, 2024
097ab01
debug
bill-buchan Apr 3, 2024
8b9fc17
Revert
bill-buchan Apr 3, 2024
1e9d51b
Force single quotes
bill-buchan Apr 3, 2024
82fbdc6
More quoting
bill-buchan Apr 3, 2024
7218162
quotes
bill-buchan Apr 3, 2024
3119c73
Quote the JSON inputs
bill-buchan Apr 3, 2024
51a494c
Prevent interpreting JSON
bill-buchan Apr 3, 2024
e51cbbd
Use base64 encoding for JSON
bill-buchan Apr 3, 2024
b65b42a
Debug output
bill-buchan Apr 3, 2024
18af9bf
Redebug
bill-buchan Apr 3, 2024
5d9552a
debug
bill-buchan Apr 3, 2024
8aea8c1
Use a cat
bill-buchan Apr 3, 2024
efd642f
Debug
bill-buchan Apr 3, 2024
bdd92b4
quotes
bill-buchan Apr 3, 2024
e1e452a
quotes
bill-buchan Apr 3, 2024
9b46a3f
Supply defaults
bill-buchan Apr 3, 2024
1736be2
Reconfigure Control Logic
bill-buchan Apr 3, 2024
a4be081
debug
bill-buchan Apr 3, 2024
7203caf
quotes
bill-buchan Apr 3, 2024
6492c1e
Reduce retry code
bill-buchan Apr 3, 2024
96929d7
debug
bill-buchan Apr 3, 2024
d14c777
debug
bill-buchan Apr 4, 2024
09827bc
Set RMAN Target
bill-buchan Apr 4, 2024
e8ec247
Missing quote
bill-buchan Apr 4, 2024
4680eb2
Set Missing RMAN Target
bill-buchan Apr 4, 2024
1fdb1b3
debug
bill-buchan Apr 4, 2024
fe07796
Debug
bill-buchan Apr 4, 2024
8f397f7
debug
bill-buchan Apr 4, 2024
0193adc
debug
bill-buchan Apr 4, 2024
51d6ee5
set variable in function
bill-buchan Apr 4, 2024
9f95bcb
debugdebug
bill-buchan Apr 4, 2024
8629bf5
Format JSON
bill-buchan Apr 4, 2024
78ce0c5
debug
bill-buchan Apr 4, 2024
44aca52
Missing dollars
bill-buchan Apr 4, 2024
10b3de8
debug
bill-buchan Apr 4, 2024
aab3a15
Ignore errors
bill-buchan Apr 4, 2024
e82f5b4
Match check
bill-buchan Apr 4, 2024
e37cc46
Handle empty variable
bill-buchan Apr 4, 2024
8744c6d
Strip quotes added for passing variable
bill-buchan Apr 4, 2024
8944418
Process quoted JSON string
bill-buchan Apr 4, 2024
3d60d58
Write raw to SSM
bill-buchan Apr 4, 2024
f026ae7
Change Backup Job Name
bill-buchan Apr 4, 2024
1ba59cd
Strip extraneous from SSM
bill-buchan Apr 4, 2024
4487f35
Do not include outer quotes in encoding
bill-buchan Apr 4, 2024
fbfbcf9
Unquote Inputs
bill-buchan Apr 4, 2024
574a799
Missing comma
bill-buchan Apr 4, 2024
5fca42d
Allow for manual inputs
bill-buchan Apr 4, 2024
970bee2
Use common element for Backup Status
bill-buchan Apr 4, 2024
c31e167
Set RMAN Target
bill-buchan Apr 4, 2024
a9f3961
Consolidate retry logic for JSON
bill-buchan Apr 4, 2024
e7d1f0b
Autocomplete fail
bill-buchan Apr 4, 2024
96afc2c
Use raw rman target
bill-buchan Apr 4, 2024
104087c
debug
bill-buchan Apr 4, 2024
33a790a
Set Phase and Status in Payload
bill-buchan Apr 4, 2024
5e9ee6f
Raw output
bill-buchan Apr 4, 2024
cdfd230
whitespace
bill-buchan Apr 4, 2024
d3c74ec
Remove Unnecessary BackupStatus element
bill-buchan Apr 4, 2024
709bdc0
Set Status during run
bill-buchan Apr 4, 2024
3ec7de1
debug
bill-buchan Apr 4, 2024
967f468
Raw output
bill-buchan Apr 5, 2024
c1d8768
Set Rman Target at correct level
bill-buchan Apr 5, 2024
49453b3
Substitute string must be quoted
bill-buchan Apr 5, 2024
d94889e
Supply the backup status
bill-buchan Apr 5, 2024
8f0ed8d
Run validate
bill-buchan Apr 5, 2024
2015bdc
Mark job done
bill-buchan Apr 5, 2024
7bf64d4
Set the Phase
bill-buchan Apr 5, 2024
ac3040a
Formatting json
bill-buchan Apr 5, 2024
10ded27
Missing dollars
bill-buchan Apr 5, 2024
bc2ad37
Debug
bill-buchan Apr 5, 2024
2027214
Set catalog credentials
bill-buchan Apr 5, 2024
adae4b6
Record a failure message
bill-buchan Apr 5, 2024
acd9363
Do not change role for rman backup
bill-buchan Apr 5, 2024
56173de
Environment required for running archivelog backups
bill-buchan Apr 5, 2024
60341aa
Force integer conversion
bill-buchan Apr 5, 2024
5bea594
Allow rerun on failure
bill-buchan Apr 5, 2024
b1e7212
Ansible 9 Porting Guide
bill-buchan Apr 5, 2024
bcb7f30
Force archivelog sequence numbers to integers
bill-buchan Apr 5, 2024
5a94f2b
Must split set facts
bill-buchan Apr 5, 2024
8da8288
Force integer conversions everywhere
bill-buchan Apr 5, 2024
99b1518
Catalog connection set within script
bill-buchan Apr 5, 2024
58a7348
Simplify message where a single archive log is missing
bill-buchan Apr 5, 2024
88316e9
Reset list of corrupt backup pieces each time
bill-buchan Apr 8, 2024
d222ef0
Set environment for RMAN command
bill-buchan Apr 8, 2024
5117b33
Supply Catalog name
bill-buchan Apr 8, 2024
130eac1
debug
bill-buchan Apr 8, 2024
8a5e13b
debug
bill-buchan Apr 8, 2024
6a6a958
Raw output
bill-buchan Apr 8, 2024
7b1ee3a
debug
bill-buchan Apr 8, 2024
71a0c4f
Commit changes made by code formatters
github-actions[bot] Apr 8, 2024
e60d876
New Delete DBIDs Job
bill-buchan Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 213 additions & 56 deletions .github/workflows/oracle-db-backup.yml

Large diffs are not rendered by default.

388 changes: 388 additions & 0 deletions .github/workflows/oracle-db-delete-dbids-not-in-use.yml

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions .github/workflows/oracle-db-validate-chunks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: "Oracle: Validate Chunks"
run-name: "Oracle: ${{ github.event_name == 'workflow_dispatch' && format('{0}_{1}_{2}', github.event.inputs.TargetEnvironment, github.event.inputs.Period, github.event.inputs.TargetHost) }}_validate_chunks"
on:
workflow_dispatch:
inputs:
TargetEnvironment:
description: "Target environment"
required: true
type: string
TargetHost:
description: "Backup target host"
required: true
type: string
VerboseOutput:
description: "Verbose Output level"
required: false
type: string
default: ""
workflow_call:
inputs:
TargetEnvironment:
description: "Target environment"
required: true
type: string
TargetHost:
description: "Backup target host"
required: true
type: string
VerboseOutput:
description: "Verbose Output level"
required: false
type: string
default: ""

# 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:
# Start deployment container job based on the build delius-ansible-aws image
deployment:
name: oracle-backup
environment: ${{ github.event.inputs.TargetEnvironment }}
runs-on: ubuntu-latest
container:
image: ghcr.io/ministryofjustice/hmpps-delius-operational-automation:0.41.0
timeout-minutes: 1440
env:
validate_command: ansible-playbook operations/playbooks/oracle_backup/validate.yml
inventory: inventory/ansible
RmanTarget: "${{ github.event.inputs.TargetHost }}"
TargetEnvironment: "${{ github.event.inputs.TargetEnvironment }}"
SSMParameter: "/oracle-backups/${{ github.event.inputs.TargetHost }}"
ansible_config: operations/playbooks/ansible.cfg
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
playbooks/ansible.cfg
path: operations
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.SourceCodeVersion || 'main' }}
fetch-depth: 0

- name: Checkout Ansible Inventory From 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: Checkout Ansible Required Roles From modernisation-platform-configuration-management
uses: actions/checkout@v4
with:
repository: ministryofjustice/modernisation-platform-configuration-management
sparse-checkout-cone-mode: false
sparse-checkout: |
ansible/roles/secretsmanager-passwords
ansible/roles/get-modernisation-platform-facts
path: roles
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: Check And Set Backup Runtime
id: check-and-set-backup-runtime
shell: bash
run: |
RUNTIME=$(aws ssm get-parameter --region ${AWS_REGION} --name "$SSMParameter" --query "Parameter.Value" --output text 2>&1) || true
PHASE=$(echo $RUNTIME | jq -r '.Phase')
STATUS=$(echo $RUNTIME | jq -r '.Status')
echo "Backup Phase and Status: $PHASE $STATUS"
if [[ $PHASE != 'Backup' ]] || [[ $STATUS != 'Success' ]]; then
echo "Backup must be successful before running Chunk Validation." && exit 1
fi
aws ssm put-parameter --region ${AWS_REGION} --name "$SSMParameter" --type String --overwrite \
--value "{\"Phase\":\"Validate Chunks\",\"Status\":\"Initializing\",\"Message\":\"Running on $RmanTarget\",\"TargetEnvironment\":\"$TargetEnvironment\",\"RmanTarget\":\"$RmanTarget\"}" \

- name: Start Ansible Validate And Fix Absent Chunks
run: |
export ANSIBLE_CONFIG=$ansible_config
ln -s $PWD/roles/ansible/roles $PWD/operations/playbooks/oracle_backup/roles
$validate_command -i $inventory -e ansible_aws_ssm_bucket_name=${{ vars.ANSIBLE_AWS_SSM_BUCKET_NAME }} -e rman_target=$RmanTarget -e fix_absent_chunks=yes ${{ github.event.inputs.VerboseOutput }}
24 changes: 21 additions & 3 deletions playbooks/oracle_backup/backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
become_method: sudo

tasks:
- name: Show Inputs
debug:
msg: "{{ json_inputs | string }}"

- name: RMAN script
block:
- name: Set database_global_database
Expand Down Expand Up @@ -62,6 +66,11 @@
catalog_options: "-n Y -c {{ catalog }}"
when: (catalog is defined)

- name: Set SSM Parameter used for Runtime details when variable is not null
set_fact:
ssm_parameter_path: '-s "{{ ssm_parameter }}"'
when: (ssm_parameter is defined)

- name: Set backup duration target when variable is not null
set_fact:
duration_options: "-m {{ rman_level_0_backup_duration_target }}"
Expand Down Expand Up @@ -90,6 +99,15 @@
enable_trace_flag: "-e Y"
when: enable_trace | default(false) | bool

# The quotes in the JSON inputs can get messed up by unwanted shell interpretation.
# To avoid this we send the JSON as an encoded string to be decoded by the shell script.
- name: Enable Repository Dispatch Event if supplied
set_fact:
repository_dispatch_flag: "-r {{ repository_dispatch }} -j {{ json_inputs | b64encode }}"
when:
- repository_dispatch is defined
- json_inputs is defined

- block:
- name: Get Current RMAN Retention
script: get_rman_retention.sh {{ database_primary_sid | default(database_standby_sid) }}
Expand Down Expand Up @@ -133,16 +151,16 @@

- name: Create RMAN Command
set_fact:
rman_command: "/home/oracle/admin/rman_scripts/rman_backup.sh -d {{ database_primary_sid | default(database_standby_sid) }} -g {{ database_global_database }} {{ rman_options }} {{ duration_options|default() }} {{ uncompress_options|default() }} {{ catalog_options|default() }} {{ enable_trace_flag|default() }}"
rman_command: "/home/oracle/admin/rman_scripts/rman_backup.sh -d {{ database_primary_sid | default(database_standby_sid) }} -g {{ database_global_database }} {{ rman_options }} {{ ssm_parameter_path | default() }} {{ duration_options|default() }} {{ uncompress_options|default() }} {{ catalog_options|default() }} {{ enable_trace_flag|default() }} {{ repository_dispatch_flag|default() }}"

- name: Show RMAN Command
debug:
msg: "About to run: {{ rman_command }}"

- name: Running RMAN script
- name: Running RMAN script in Background
shell: "{{ rman_command }}"
async: "{{ allowable_duration|default(28800) }}"
poll: 60
poll: 0
environment:
ASSUME_ROLE_NAME: "{{ secretsmanager_passwords['catalog'].assume_role_name | default() }}"
SECRET_ACCOUNT_ID: "{{ account_ids[secretsmanager_passwords['catalog'].account_name] | default() }}"
Expand Down
2 changes: 1 addition & 1 deletion playbooks/oracle_backup/files/get_rman_backups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export NUM_OF_DAYS_BACK_TO_VALIDATE="${1:-0}"
if [[ "${CATALOG}" != "NOCATALOG" ]]
then
get_rman_password
CONNECT_TO_CATALOG="connect catalog ${CATALOG_CREDENTIALS}"
CONNECT_TO_CATALOG="connect catalog rcvcatowner/${RMANPASS}@${CATALOG}"
fi

# Get list of RMAN backups from the Catalog; merge the Availability and Handle Lines
Expand Down
17 changes: 17 additions & 0 deletions playbooks/oracle_backup/files/list_github_environments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import requests
import os

token = os.getenv('GITHUB_TOKEN')
repository = os.getenv('GITHUB_REPOSITORY')

url = f"https://api.github.com/repos/{repository}/environments"
headers = {
'Authorization': f'token {token}',
'Accept': 'application/vnd.github+json',
}

response = requests.get(url, headers=headers)
environments = response.json()

for env in environments['environments']:
print(env['name'])
Loading
Loading