Skip to content

Commit 27cb606

Browse files
feat: workflow for S3 disaster recovery
1 parent 8f163fa commit 27cb606

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: . ⚠️⚠️⚠️ Recover S3 Repository back in time ⚠️⚠️⚠️
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
date_time:
7+
description: 'UTC DateTime to recover the S3 repository back in time (MM-DD-YYYY HH:MM:SS +0)'
8+
type: string
9+
required: true
10+
path:
11+
description: 'Path under infrastructure_agent folder to recover (w/o leading slash, with trailing slash)'
12+
type: string
13+
required: true
14+
environment:
15+
type: choice
16+
required: true
17+
description: 'Environment to run the action'
18+
options:
19+
- staging
20+
- production
21+
default: 'staging'
22+
23+
env:
24+
MANDATORY_PREFIX: 'infrastructure_agent/'
25+
IMAGE: 'ghcr.io/newrelic-forks/s3-pit-restore:latest'
26+
AWS_REGION: "us-east-1"
27+
TEMP_AWS_PROFILE: temp_aws_profile
28+
29+
jobs:
30+
recover-s3-repository:
31+
name: Execute S3 PIT restore
32+
runs-on: ubuntu-20.04
33+
steps:
34+
- name: Validate datetime
35+
run: |
36+
datetime="${{ github.event.inputs.date_time }}"
37+
# Use Python's strptome (same as s3-pit-restore) to check if it's a valid datetime
38+
python3 -c "from datetime import datetime; datetime.strptime('$datetime', '%m-%d-%Y %H:%M:%S %z')" 2> /dev/null
39+
exit_code=$?
40+
if [ $exit_code -ne 0 ]]; then
41+
exit 1
42+
fi
43+
44+
- name: Validate path input does not have leading nor trailing slash
45+
run: |
46+
s3_path="${{ github.event.inputs.path }}"
47+
# Check if the path has a leading slash
48+
if [[ "$s3_path" == /* ]]; then
49+
echo "Invalid path: should not have a leading slash."
50+
return 1
51+
fi
52+
53+
# Check if the path has a trailing slash
54+
if [[ "$s3_path" == */ ]]; then
55+
echo "Invalid path: should not have a trailing slash."
56+
return 1
57+
fi
58+
59+
- name: Checkout repository
60+
uses: actions/checkout@v4
61+
with:
62+
repository: newrelic-forks/s3-pit-restore
63+
ref: master
64+
65+
- name: Setup AWS credentials for Production
66+
if: ${{ env.ENVIRONMENT == 'production' }}
67+
run: |
68+
./setup_aws_credentials.sh
69+
env:
70+
AWS_ACCESS_KEY_ID: ${{ secrets.OHAI_AWS_ACCESS_KEY_ID_PRODUCTION }}
71+
AWS_SECRET_ACCESS_KEY: ${{ secrets.OHAI_AWS_SECRET_ACCESS_KEY_PRODUCTION }}
72+
AWS_ROLE_ARN: ${{ secrets.OHAI_AWS_ROLE_ARN_PRODUCTION }}
73+
AWS_ROLE_SESSION_NAME: ${{ secrets.OHAI_AWS_ROLE_SESSION_NAME_PRODUCTION }}
74+
TEMP_AWS_PROFILE: ${{ env.TEMP_AWS_PROFILE }}
75+
76+
- name: Run S3 PIT restore
77+
if: ${{ env.ENVIRONMENT == 'production' }}
78+
run: |
79+
BUCKET="nr-downloads-main" \
80+
PREFIX="${{ env.MANDATORY_PREFIX }}${{ github.event.inputs.path }}" \
81+
TIME="${{ github.event.inputs.date_time }}" \
82+
IMAGE="${{ env.IMAGE }}" \
83+
AWS_PROFILE="${{ env.TEMP_AWS_PROFILE }}" \
84+
make restore
85+
86+
- name: Setup AWS credentials for Staging
87+
if: ${{ env.ENVIRONMENT == 'staging' }}
88+
run: |
89+
./setup_aws_credentials.sh
90+
env:
91+
AWS_ACCESS_KEY_ID: ${{ secrets.OHAI_AWS_ACCESS_KEY_ID_STAGING }}
92+
AWS_SECRET_ACCESS_KEY: ${{ secrets.OHAI_AWS_SECRET_ACCESS_KEY_STAGING }}
93+
AWS_ROLE_ARN: ${{ secrets.OHAI_AWS_ROLE_ARN_STAGING }}
94+
AWS_ROLE_SESSION_NAME: ${{ secrets.OHAI_AWS_ROLE_SESSION_NAME_STAGING }}
95+
TEMP_AWS_PROFILE: ${{ env.TEMP_AWS_PROFILE }}
96+
97+
- name: Run S3 PIT restore in Staging S3
98+
if: ${{ env.ENVIRONMENT == 'staging' }}
99+
run: |
100+
BUCKET="nr-downloads-ohai-staging" \
101+
PREFIX="${{ env.MANDATORY_PREFIX }}${{ env.S3_PATH }}" \
102+
TIME="${{ env.DATETIME }}" \
103+
IMAGE="${{ env.IMAGE }}" \
104+
AWS_PROFILE="${{ env.TEMP_AWS_PROFILE }}" \
105+
make restore

0 commit comments

Comments
 (0)