|
| 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 | + |
| 15 | +env: |
| 16 | + BUCKET: 'nr-downloads-main' |
| 17 | + MANDATORY_PREFIX: 'infrastructure_agent/' |
| 18 | + IMAGE: 'ghcr.io/newrelic-forks/s3-pit-restore:latest' |
| 19 | + |
| 20 | +jobs: |
| 21 | + recover-s3-repository: |
| 22 | + name: Execute S3 PIT restore |
| 23 | + runs-on: ubuntu-20.04 |
| 24 | + steps: |
| 25 | + - name: Validate datetime |
| 26 | + run: | |
| 27 | + datetime="${{ github.event.inputs.date_time }}" |
| 28 | + # Use Python's strptome (same as s3-pit-restore) to check if it's a valid datetime |
| 29 | + python3 -c "from datetime import datetime; datetime.strptime('$datetime', '%m-%d-%Y %H:%M:%S %z')" 2> /dev/null |
| 30 | + exit_code=$? |
| 31 | + |
| 32 | + if [ $exit_code -ne 0 ]]; then |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | +
|
| 36 | + - name: Validate path input does not have leading slash and has trailing slash |
| 37 | + run: | |
| 38 | + path="${{ github.event.inputs.path }}" |
| 39 | + # Check if the path has a leading slash |
| 40 | + if [[ "$path" == /* ]]; then |
| 41 | + echo "Invalid path: should not have a leading slash." |
| 42 | + return 1 |
| 43 | + fi |
| 44 | + |
| 45 | + # Check if the path has a trailing slash |
| 46 | + if [[ "$path" != */ ]]; then |
| 47 | + echo "Invalid path: should have a trailing slash." |
| 48 | + return 1 |
| 49 | + fi |
| 50 | + |
| 51 | + - name: Checkout repository |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + repository: newrelic-forks/s3-pit-restore |
| 55 | + ref: master |
| 56 | + |
| 57 | + - name: Run S3 PIT restore |
| 58 | + run: | |
| 59 | + AWS_PROFILE=primary/okta_onhostintegrations \ |
| 60 | + BUCKET="nr-downloads-main" \ |
| 61 | + PREFIX="${{ env.MANDATORY_PREFIX }}${{ github.event.inputs.path }}" \ |
| 62 | + TIME="${{ github.event.inputs.date_time }}" \ |
| 63 | + IMAGE="${{ env.IMAGE }}" \ |
| 64 | + make restore |
0 commit comments