How to setup Azure Automation account to restore database on SQL MI ?
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"