SQLMI-Restore-Automation-DR
Version 1.1 by Nikhil Singh on 2025/10/01 09:41
Script Overview:
The PowerShell script automates the following key steps to perform a geo-restore of a managed instance database from the production SQLMI to the DR SQLMI, including handling the Managed Instance storage scaling, restore verification, and cleanup.
Script Breakdown
- Set Variables:
Define Azure subscription, resource group, Managed Instance names, database names, storage sizes, and logging locations. - Initialize Logs:
Create log folder if it doesn’t exist. - Connect to Azure:
Login and set the subscription context. - Start Managed Instance:
Check if the DR Managed Instance is running; start it if stopped. - Increase Storage Size:
Temporarily increase storage to allow room for the database restore. - Restore Database:
Perform a geo-restore of the production database to the DR Managed Instance. - Wait for Restore to Complete:
Monitor until the restored database is online. - Delete Restored Database:
Remove the restored database to clean up space - Reduce Storage Size:
Scale storage back down to the original minimal size. - Stop Managed Instance:
Shut down the Managed Instance to save costs. - Write Logs and Upload:
Save detailed logs and a summary report, then upload them to Azure Blob Storage.