Skip to content

Commit

Permalink
Adjusted DB_INIT_FILE_LOCATION name/handling/output
Browse files Browse the repository at this point in the history
Removed DB_LOCAL_SQL_INIT_FILE
Add skip database backups cleaning due to PVC cleanup being disabled
  • Loading branch information
warrenchristian1telus committed Oct 11, 2024
1 parent e5b5f3d commit be9b048
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 52 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ LOG_SLACK_WEBHOOK_URL=

# Database configuration
# Optional (init.sql.gz or init.sql) backup file to use for initialization (not stored in repo)
DB_LOCAL_SQL_INIT_FILE=./temp/db-backups/dev-mysql-performance-db_2024-09-04_12-00-34.sql.gz
REMOTE_BACKUP_FILE_LOCATION=init.sql.gz # Expected storage on db-backup-storage mounted PVC (which is detected automatically)
DB_INIT_FILE_LOCATION=init.sql.gz # Expected storage on db-backup-storage mounted PVC (which is detected automatically)
# Entries to accommodate MySQL and/or MariaDB Environments
DB_BACKUP_DEPLOYMENT_NAME=performance-db # "-backup-storage" will be appended to this with the helm installation
DB_BACKUP_DEPLOYMENT_FULL_NAME=performance-db-backup-storage
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ jobs:
CRON_IMAGE: ${{ env.CRON_IMAGE}}
REDIS_IMAGE: ${{ env.REDIS_IMAGE }}
REDIS_NAME: ${{ env.REDIS_NAME }}
DB_LOCAL_SQL_INIT_FILE: ${{ env.DB_LOCAL_SQL_INIT_FILE }}
REMOTE_BACKUP_FILE_LOCATION: ${{ env.REMOTE_BACKUP_FILE_LOCATION }}
DB_INIT_FILE_LOCATION: ${{ env.DB_INIT_FILE_LOCATION }}
DB_BACKUP_DEPLOYMENT_NAME: ${{ env.DB_BACKUP_DEPLOYMENT_NAME }}
DB_BACKUP_DEPLOYMENT_FULL_NAME: ${{ env.DB_BACKUP_DEPLOYMENT_FULL_NAME }}
BACKUP_IMAGE: ${{ env.BACKUP_IMAGE }}
Expand Down Expand Up @@ -214,8 +213,7 @@ jobs:
DB_PORT: ${{ needs.checkEnv.outputs.DB_PORT }}
DB_NAME: ${{ needs.checkEnv.outputs.DB_NAME }}
DB_DATABASE: ${{ needs.checkEnv.outputs.DB_DATABASE }}
DB_LOCAL_SQL_INIT_FILE: ${{ needs.checkEnv.outputs.DB_LOCAL_SQL_INIT_FILE }}
REMOTE_BACKUP_FILE_LOCATION: ${{ needs.checkEnv.outputs.REMOTE_BACKUP_FILE_LOCATION }}
DB_INIT_FILE_LOCATION: ${{ needs.checkEnv.outputs.DB_INIT_FILE_LOCATION }}
DB_HEALTH_QUERY: ${{ needs.checkEnv.outputs.DB_HEALTH_QUERY }}
DB_BACKUP_DEPLOYMENT_NAME: ${{ needs.checkEnv.outputs.DB_BACKUP_DEPLOYMENT_NAME }}
DB_BACKUP_DEPLOYMENT_FULL_NAME: ${{ needs.checkEnv.outputs.DB_BACKUP_DEPLOYMENT_FULL_NAME }}
Expand Down
46 changes: 25 additions & 21 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -307,26 +307,30 @@ jobs:
run: |
echo "Checking Helm release status for '${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }}'..."
# Temporarily disable exit on error
set +e
# Capture the output and exit code of the helm status command
HELM_STATUS_OUTPUT=$(helm status ${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }} 2>&1)
HELM_STATUS_EXIT_CODE=$?
# Re-enable exit on error
set -e
echo "Helm status output: $HELM_STATUS_OUTPUT"
echo "Helm status exit code: $HELM_STATUS_EXIT_CODE"
# Check if the Helm release is deployed or not found
if [ $HELM_STATUS_EXIT_CODE -eq 0 ]; then
echo "Helm release '${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }}' is deployed. Proceeding with uninstallation..."
helm uninstall ${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }}
elif echo "$HELM_STATUS_OUTPUT" | grep -qi "release: not found"; then
echo "Helm release '${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }}' not found. Skipping uninstallation..."
if [ ${{ inputs.CLEAN_PVC }} -eq "YES" ]; then
# Temporarily disable exit on error
set +e
# Capture the output and exit code of the helm status command
HELM_STATUS_OUTPUT=$(helm status ${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }} 2>&1)
HELM_STATUS_EXIT_CODE=$?
# Re-enable exit on error
set -e
echo "Helm status output: $HELM_STATUS_OUTPUT"
echo "Helm status exit code: $HELM_STATUS_EXIT_CODE"
# Check if the Helm release is deployed or not found
if [ $HELM_STATUS_EXIT_CODE -eq 0 ]; then
echo "Helm release '${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }}' is deployed. Proceeding with uninstallation..."
helm uninstall ${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }}
elif echo "$HELM_STATUS_OUTPUT" | grep -qi "release: not found"; then
echo "Helm release '${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }}' not found. Skipping uninstallation..."
else
echo "Unexpected error checking Helm release status: $HELM_STATUS_OUTPUT"
exit 1
fi
else
echo "Unexpected error checking Helm release status: $HELM_STATUS_OUTPUT"
exit 1
echo "Cleaning backups skipped due to PVC cleanup being disabled."
fi
8 changes: 2 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ on:
APP_NAME:
required: true
type: string
DB_LOCAL_SQL_INIT_FILE:
required: true
type: string
REMOTE_BACKUP_FILE_LOCATION:
DB_INIT_FILE_LOCATION:
required: true
type: string
WEB_NAME:
Expand Down Expand Up @@ -198,8 +195,7 @@ jobs:
exec: bash ./openshift/scripts/deploy-database-backups.sh
env:
APP_NAME: ${{ inputs.APP_NAME }}
DB_LOCAL_SQL_INIT_FILE: ${{ inputs.DB_LOCAL_SQL_INIT_FILE }}
REMOTE_BACKUP_FILE_LOCATION: ${{ inputs.REMOTE_BACKUP_FILE_LOCATION }}
DB_INIT_FILE_LOCATION: ${{ inputs.DB_INIT_FILE_LOCATION }}
DB_BACKUP_DEPLOYMENT_NAME: ${{ inputs.DB_BACKUP_DEPLOYMENT_NAME }}
DB_BACKUP_DEPLOYMENT_FULL_NAME: ${{ inputs.DB_BACKUP_DEPLOYMENT_FULL_NAME }}
BACKUP_HELM_CHART: ${{ inputs.BACKUP_HELM_CHART }}
Expand Down
31 changes: 12 additions & 19 deletions openshift/scripts/deploy-database-backups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ extract_backup_info() {
echo "Use%: $USE_PERCENT"
echo "Mounted on: $MOUNTED_ON"

# Prepend mounted on value to REMOTE_BACKUP_FILE_LOCATION
REMOTE_BACKUP_FILE_LOCATION="$MOUNTED_ON/$REMOTE_BACKUP_FILE_LOCATION"
echo "Updated REMOTE_BACKUP_FILE_LOCATION: $REMOTE_BACKUP_FILE_LOCATION"
# Prepend mounted on value to DB_INIT_FILE_LOCATION
DB_INIT_FILE_LOCATION="$MOUNTED_ON/$DB_INIT_FILE_LOCATION"
echo "Updated DB_INIT_FILE_LOCATION: $DB_INIT_FILE_LOCATION"

# Add notice if Use% is greater than 70% or less than 1%
USE_PERCENT_VALUE=$(echo "$USE_PERCENT" | tr -d '%')
Expand Down Expand Up @@ -102,7 +102,7 @@ list_backups() {
fi

if [ -z "$BACKUP_POD" ]; then
echo "No pods found in Running state ($BACKUP_POD). Retrying in $WAIT_TIME seconds..."
# echo "No pods found in Running state ($BACKUP_POD). Retrying in $WAIT_TIME seconds..."
sleep $WAIT_TIME
fi
done
Expand All @@ -113,18 +113,11 @@ list_backups() {
extract_backup_info "$BACKUP_LIST"

# Check if the backup list contains the remote backup file location
#!!! Also ensure local backuup file exists as wwell
if ! echo "$BACKUP_LIST" | grep -q "$REMOTE_BACKUP_FILE_LOCATION"; then
echo "Remote backup file not found in the backup list. Copying the local file to the backup pod..."
if [[ -f "$DB_LOCAL_SQL_INIT_FILE" ]]; then
if ! oc cp --retries=25 "$DB_LOCAL_SQL_INIT_FILE" "$BACKUP_POD:$REMOTE_BACKUP_FILE_LOCATION"; then
echo "Error: Failed to copy the local file to the backup pod."
exit 1
fi
else
echo "Local SQL backup file not found. Please check your file exists and path is valid in env: DB_LOCAL_SQL_INIT_FILE"
fi
echo "File copied successfully."
if ! echo "$BACKUP_LIST" | grep -q "$DB_INIT_FILE_LOCATION"; then
echo "Remote backup file location NOT FOUND in the backup list."
echo "Backup file location: $DB_INIT_FILE_LOCATION"
echo "Backup list: $BACKUP_LIST"
exit 1
fi

# Parse the backup list into an array
Expand All @@ -148,8 +141,8 @@ list_backups() {
# Only include entries with size > 1M
if [ "$SIZE_IN_BYTES" -gt $((1 * 1024 * 1024)) ]; then
echo "$SIZE $DATE $FILENAME"
else
echo "Skipped small backup: $FILENAME"
# else
# echo "Skipped small backup: $FILENAME"
fi
done | sort -k2,3r)

Expand All @@ -167,7 +160,7 @@ restore_database_from_backup() {
echo "Listing available backups..."
LATEST_BACKUP_FILENAME=$(list_backups)

# Check if the file exists and has a .gz or .sql extension
# Check if the file exists
if [[ -f "$LATEST_BACKUP_FILENAME" ]]; then
# Restore the backup using the filename
restore_backup_from_file "$LATEST_BACKUP_FILENAME"
Expand Down

0 comments on commit be9b048

Please sign in to comment.