Automated MySQL database backup solution with Azure integration for non-production environments.
This script creates secure, manual backups of non-production MySQL databases with the following features:
- Creates complete dumps of multiple non-production databases
- Uses SecureString (DPAPI) for password storage
- Cleans up backups older than 7 days
- Uploads backups to Azure File Share
- Provides detailed logging of all operations
Navigate to Azure Portal:
- In the search bar, type "AKV-OBOBA-EUS-NONPROD-001" and open the Key Vault
- Under "Objects" section, click on "Secrets"
- Find and click on the secret named "db-password"
- Click "Show Secret" to reveal the value
- Copy the secret value
Use the Azure Key Vault secret value in the next command:
Read-Host "Enter MySQL password" -AsSecureString |
ConvertFrom-SecureString |
Set-Content C:\Scripts\Manual_db_backups_nonprod_pwd.txtNavigate to Azure Portal:
- In the search bar, type "saobobanonprod001" and open the Storage Account
- Under "Security + networking" section, click on "Access keys"
- Find "key1" and click "Show" to reveal the key
- Copy the access key value
Use the Azure Storage Account Access Key in the next command:
Read-Host "Enter Storage Account Access Key" -AsSecureString |
ConvertFrom-SecureString |
Set-Content C:\Scripts\Manual_db_backups_nonprod_storage_key.txt-
Navigate to the script directory:
cd C:\Scripts
-
Execute the backup script:
.\Manual_db_backups_nonprod.ps1
-
Connection Setup
- Loads stored credentials securely
- Establishes connection to MySQL database
- Verifies Azure Storage access
-
Backup Process
- Creates a timestamped SQL dump file
- Saves to:
C:\sql_backup\dev\backup_oboba_cms_db_dev_<timestamp>.sqlC:\sql_backup\qa\backup_oboba_cms_db_qa_<timestamp>.sqlC:\sql_backup\stage\backup_oboba_cms_db_stage_<timestamp>.sqlC:\sql_backup\uat\backup_oboba_cms_db_<timestamp>.sql - Logs all actions to:
C:\sql_backup\logs\Manual_backup_nonprod_<timestamp>.log
-
Cloud Sync
- Uploads the backup to Azure File Share:
saobobanonprod001/mysql-backups-nonprod/ - Organizes files in subfolders by environment (dev/qa/stage/uat)
- Verifies successful upload
- Uploads the backup to Azure File Share:
-
Cleanup
- Removes local backups older than 7 days
- Cleans up old backups in Azure File Share
- Securely clears all sensitive data from memory