Database Export and Import Scheduler #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Database Export and Import Scheduler | |
on: | |
workflow_dispatch: | |
inputs: | |
fromEnv: | |
description: 'Select Environment to Export' | |
required: true | |
type: choice | |
options: | |
- COOP_Dev | |
- COOP_Prod | |
- Ruhunu_Prod | |
- MP_Prod | |
toEnv: | |
description: 'Select Environment to Import' | |
required: true | |
type: choice | |
options: | |
- QA | |
date: | |
description: 'Select Scheduling Date (YYYY-MM-DD)' | |
required: true | |
jobs: | |
schedule_export_import: | |
name: Schedule Export & Import | |
runs-on: ubuntu-latest | |
steps: | |
- name: Run Scheduler on Remote Server | |
env: | |
SERVER_IP: ${{ secrets.OBSERVABILITY_SERVER_IP }} | |
SERVER_SSH_KEY: ${{ secrets.OBSERVABILITY_SSH_PRIVATE_KEY }} | |
FROM_ENV: ${{ inputs.fromEnv }} | |
TO_ENV: ${{ inputs.toEnv }} | |
DATE: ${{ inputs.date }} | |
run: | | |
echo "$SERVER_SSH_KEY" > private_key.pem | |
chmod 600 private_key.pem | |
UTC_TIME=$(date -d "${DATE}T02:00:00+05:30" -u "+%H:%M %Y-%m-%d") | |
HOUR=$(echo "$UTC_TIME" | awk '{print $1}' | cut -d':' -f1) | |
MINUTE=$(echo "$UTC_TIME" | awk '{print $1}' | cut -d':' -f2) | |
UTC_DATE=$(echo "$UTC_TIME" | awk '{print $2}') | |
ssh -o StrictHostKeyChecking=no -i private_key.pem azureuser@$SERVER_IP " | |
echo '/home/azureuser/utils/db_utils/db_export_import_scheduler.sh $FROM_ENV $TO_ENV' | at $HOUR:$MINUTE $UTC_DATE | |
" | |
rm private_key.pem |