Wiki source code of SQLMI-Restore-Automation-DR

Version 1.1 by Nikhil Singh on 2025/10/01 09:41

Show last authors
1 === Script Overview: ===
2
3 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.
4
5
6 === Script Breakdown ===
7
8 1. **Set Variables:**
9 Define Azure subscription, resource group, Managed Instance names, database names, storage sizes, and logging locations.
10 1. **Initialize Logs:**
11 Create log folder if it doesn’t exist.
12 1. **Connect to Azure:**
13 Login and set the subscription context.
14 1. **Start Managed Instance:**
15 Check if the DR Managed Instance is running; start it if stopped.
16 1. **Increase Storage Size:**
17 Temporarily increase storage to allow room for the database restore.
18 1. **Restore Database:**
19 Perform a geo-restore of the production database to the DR Managed Instance.
20 1. **Wait for Restore to Complete:**
21 Monitor until the restored database is online.
22 1. **Delete Restored Database:**
23 Remove the restored database to clean up space
24 1. **Reduce Storage Size:**
25 Scale storage back down to the original minimal size.
26 1. **Stop Managed Instance:**
27 Shut down the Managed Instance to save costs.
28 1. **Write Logs and Upload:**
29 Save detailed logs and a summary report, then upload them to Azure Blob Storage.