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

  1. Set Variables:
    Define Azure subscription, resource group, Managed Instance names, database names, storage sizes, and logging locations.
  2. Initialize Logs:
    Create log folder if it doesn’t exist.
  3. Connect to Azure:
    Login and set the subscription context.
  4. Start Managed Instance:
    Check if the DR Managed Instance is running; start it if stopped.
  5. Increase Storage Size:
    Temporarily increase storage to allow room for the database restore.
  6. Restore Database:
    Perform a geo-restore of the production database to the DR Managed Instance.
  7. Wait for Restore to Complete:
    Monitor until the restored database is online.
  8. Delete Restored Database:
    Remove the restored database to clean up space
  9. Reduce Storage Size:
    Scale storage back down to the original minimal size.
  10. Stop Managed Instance:
    Shut down the Managed Instance to save costs.
  11. Write Logs and Upload:
    Save detailed logs and a summary report, then upload them to Azure Blob Storage.
Tags:
    

Need help?

If you need help with XWiki you can contact: