How to setup Azure Automation account to restore database on SQL MI ?

Anoop Noel Nakkala 0 Reputation points
2024-07-23T20:11:08.8833333+00:00

Hello,

I have a PowerShell script (see below) that I currently run daily from a task scheduler on a VM to restore a production database (SQL Managed Instance) to a secondary instance (SQL Managed Instance).

I am planning to move this process to an Azure Automation Account. As I am new to using Azure Automation Accounts, I need assistance with understanding the necessary permissions required when using a service principal and managed identity to achieve this.

I need to set up the script below to run from the Azure Automation Account.


Select-AzSubscription xxx-xxxx-subscription

$utcTimeMinusTwoHours = (Get-Date).ToUniversalTime().AddHours(-2)

Format the time

$formattedTime = $utcTimeMinusTwoHours.ToString("yyyy-MM-dd HH:mm:ss")

Restore-AzSqlInstanceDatabase -FromPointInTimeBackup -Name "MyDB" -InstanceName "MySourceMIinstance" -ResourceGroupName "SourceResourceGrp" -PointInTime $formattedTime -TargetInstanceDatabaseName "MyTargetDB" -TargetInstanceName "MyTargetMI" -TargetResourceGroupName "MyTargetResourceGroup"

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,366 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,196 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,332 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,634 questions
0 comments No comments
{count} votes