Restore database across servers(Azure SQL Database and Azure SQL managed instance)- Azure Automation

Published Aug 30 2021 12:05 AM 1,450 Views
Microsoft

In this article, you will find the required steps and setup to restore your Azure SQL database from one Azure SQL server to another Azure SQL server. The provided method can be applied on both Azure SQL database and Azure SQL server with few differences that will be discussed later in this article in detail.

 

One of the common scenarios to use this approach is when customers would like to have an automated and scheduled job to retsore a database from production to development environment for development reasons.

 

In the below steps, we will be using Azure Automation and PowerShell Runbook commands to restore the database on another Azure SQL server\instance:

 

1. Access your Azure portal and create a new Azure Automation account if you don’t have an existing one, and you can follow this link for the required steps.  

 

Note: it’s required to set “create Azure Run As Account” to yes in order to run the PowerShell script later successfully. In case this value cannot be set to yes in your environment it will require to enable managed identity to Azure automation and you can check this link for more information about this preview.

 

Sabrin_Alsahsah_0-1628684793251.png

 

2. When your automation account is created successfully, create a new PowerShell Runbook by accessing your Azure automation account -> Runbooks blade -> create a runbook and fill the required fields, and chose PowerShell as the Runbook type (as below).

 

Sabrin_Alsahsah_2-1628685287898.png

 

For more information, you can check this link.

 

3. Import the below modules to your PowerShell runbook by accessing module gallery blade:

    1. Az.Accounts
    2. Az.Automation
    3. Az.Compute
    4. Az.sql

 

Sabrin_Alsahsah_3-1628685720043.png

 

4. Add one of the below PowerShell commands to your runbook based on your Azure SQL resource type, if its Azure SQL database or Azure SQL managed instance.

 

Azure SQL database

Notes:

  • The below script will use Geo Restore to retsore the database from one Azure SQL server to another Azure SQL server. Geo-restore is available only for SQL databases configured with geo-redundant backup storage and you can have more information by accessing this link.
  • The script will include a remove database command as it will remove the existing database and restore a new copy. 
  • You can adjust the service tier level on the script as required.

 

 

 

 

Import-Module Az.Accounts
Import-Module Az.Automation
Import-Module Az.Compute
Import-Module Az.sql

# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process

$connection = Get-AutomationConnection -Name AzureRunAsConnection

while(!($connectionResult) -and ($logonAttempt -le 10))
{
    $LogonAttempt++
    # Logging in to Azure...
    $connectionResult = Connect-AzAccount `
                            -ServicePrincipal `
                            -Tenant $connection.TenantID `
                            -ApplicationId $connection.ApplicationID `
                            -CertificateThumbprint $connection.CertificateThumbprint

    Start-Sleep -Seconds 30
}

$subscriptionId = "******"
$resourceGroupName = "******"
$ServerName = "******"
$TargetServerName= "******"
$databaseName = "******"
$targetDatabase = "******"

Get-AzSubscription -SubscriptionId $subscriptionId
Select-AzSubscription -SubscriptionId $subscriptionId

Remove-AzSqlDatabase -ResourceGroupName $resourceGroupName -ServerName $TargetServerName -DatabaseName $targetDatabase -Force

$GeoBackup = Get-AzSqlDatabaseGeoBackup -ResourceGroupName $resourceGroupName -ServerName $ServerName -DatabaseName $databaseName

Restore-AzSqlDatabase -FromGeoBackup -ResourceGroupName $resourceGroupName -ServerName $TargetServerName -TargetDatabaseName $targetDatabase -ResourceId $GeoBackup.ResourceID -Edition "Standard" -ServiceObjectiveName "S2"

 

 

 

 

Azure SQL managed instance

 

Notes:

  • The below script will use Point In Time Restore (PITR) to restore a copy of the database from one Azure SQL isnatnce to another Azure SQL insatnce. You can have more information by accessing this link.
  • The script will include a remove database command as it will remove the old copy and create a new one as a copy.
  • The script will retsore the database to before 30 minutes, this can be adjuested as requried. 
  • You can adjust the service tier level on the script as required.

 

 

 

Import-Module Az.Accounts
Import-Module Az.Automation
Import-Module Az.Compute
Import-Module Az.sql
$connectionName = "AzureRunAsConnection"
try
{
     # Get the connection "AzureRunAsConnection "
     $servicePrincipalConnection = Get-AutomationConnection -Name $connectionName       
"Logging in to Azure..."
Connect-AzAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
              -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
     if (!$servicePrincipalConnection)
        {
         $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
       } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
       }
}
 
Set-azContext -SubscriptionId "********"
$targetResourceGroupName = "********"
$targetInstanceName = "********"
$targetDatabase = "********"
$subscriptionId = "********"
$resourceGroupName = "********"
$managedInstanceName = "********"
$databaseName = "********"
$pointInTime = (Get-Date).AddMinutes(-30)
Remove-AzSqlInstanceDatabase -Name $targetDatabase -InstanceName $targetInstanceName -ResourceGroupName $targetResourceGroupName  -Force
Restore-AzSqlInstanceDatabase -FromPointInTimeBackup -ResourceGroupName $resourceGroupName -InstanceName $managedInstanceName -Name $databaseName -PointInTime $pointInTime -     TargetInstanceDatabaseName $targetDatabase -

 

 

 

 

5. Create a schedule for your runbook by following the steps in this link, and make sure to link it with your runbook.

 

Sabrin_Alsahsah_4-1628686127817.png

 

6. Test running the runbook and make sure you are not receiving any errors in the errors sections.

 

Sabrin_Alsahsah_5-1628686146950.png

 

I hope this article was helpful for you, please feel free to share your feedback in the comments section. 

 

Sabrin Alsahsah

 

 

1 Comment
Occasional Visitor

@Sabrin_Alsahsah Thanks for the article,  Is it possible to restore the DB across servers in different subscriptions?

%3CLINGO-SUB%20id%3D%22lingo-sub-2636181%22%20slang%3D%22en-US%22%3ERestore%20database%20across%20servers(Azure%20SQL%20Database%20and%20Azure%20SQL%20managed%20instance)-%20Azure%20Automation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2636181%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20this%20article%2C%20you%20will%20find%20the%20required%20steps%20and%20setup%20to%20restore%20your%20Azure%20SQL%20database%20from%20one%20Azure%20SQL%20server%20to%20another%20Azure%20SQL%20server.%20The%20provided%20method%20can%20be%20applied%20on%20both%20Azure%20SQL%20database%20and%20Azure%20SQL%20server%20with%20few%20differences%20that%20will%20be%20discussed%20later%20in%20this%20article%20in%20detail.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20of%20the%20common%20scenarios%20to%20use%20this%20approach%20is%20when%20customers%20would%20like%20to%20have%20an%20automated%20and%20scheduled%20job%20to%20retsore%20a%20database%20from%20production%20to%20development%20environment%20for%20development%20reasons.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20below%20steps%2C%20we%20will%20be%20using%20Azure%20Automation%20and%20PowerShell%20Runbook%20commands%20to%20restore%20the%20database%20on%20another%20Azure%20SQL%20server%5Cinstance%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20Access%20your%20Azure%20portal%20and%20create%20a%20new%20Azure%20Automation%20account%20if%20you%20don%E2%80%99t%20have%20an%20existing%20one%2C%20and%20you%20can%20follow%20this%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fautomation%2Fautomation-create-standalone-account%23create-a-new-automation-account-in-the-azure-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Elink%3C%2FA%3E%20for%20the%20required%20steps.%20%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%3CU%3E%3CSTRONG%3ENote%3A%3C%2FSTRONG%3E%3C%2FU%3E%20it%E2%80%99s%20required%20to%20set%20%E2%80%9C%3C%2FSPAN%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3Ecreate%20Azure%20Run%20As%20Account%3C%2FSTRONG%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%E2%80%9D%20to%20yes%20in%20order%20to%20run%20the%20PowerShell%20script%20later%20successfully.%20In%20case%20this%20value%20cannot%20be%20set%20to%20yes%20in%20your%20environment%20it%20will%20require%20to%20enable%20managed%20identity%20to%20Azure%20automation%20and%20you%20can%20check%20this%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fautomation%2Fenable-managed-identity-for-automation%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Elink%3C%2FA%3E%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3Efor%20more%20information%20about%20this%20preview.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sabrin_Alsahsah_0-1628684793251.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302355i074331C924355345%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Sabrin_Alsahsah_0-1628684793251.png%22%20alt%3D%22Sabrin_Alsahsah_0-1628684793251.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2.%20When%20your%20automation%20account%20is%20created%20successfully%2C%20create%20a%20new%20PowerShell%20Runbook%20by%20accessing%20your%20Azure%20automation%20account%20-%26gt%3B%20Runbooks%20blade%20-%26gt%3B%20create%20a%20runbook%20and%20fill%20the%20required%20fields%2C%20and%20chose%20%3CU%3EPowerShell%20%3C%2FU%3Eas%20the%20Runbook%20type%20(as%20below).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sabrin_Alsahsah_2-1628685287898.png%22%20style%3D%22width%3A%20567px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302357iA3D6731841880430%2Fimage-dimensions%2F567x253%3Fv%3Dv2%22%20width%3D%22567%22%20height%3D%22253%22%20role%3D%22button%22%20title%3D%22Sabrin_Alsahsah_2-1628685287898.png%22%20alt%3D%22Sabrin_Alsahsah_2-1628685287898.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20more%20information%2C%20you%20can%20check%20this%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fautomation%2Flearn%2Fautomation-tutorial-runbook-textual%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Elink%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3.%20Import%20the%20below%20modules%20to%20your%20PowerShell%20runbook%20by%20accessing%20module%20gallery%20blade%3A%3C%2FP%3E%0A%3COL%20class%3D%22lia-list-style-type-lower-alpha%22%3E%0A%3COL%20class%3D%22lia-list-style-type-lower-alpha%22%3E%0A%3CLI%3EAz.Accounts%3C%2FLI%3E%0A%3CLI%3EAz.Automation%3C%2FLI%3E%0A%3CLI%3EAz.Compute%3C%2FLI%3E%0A%3CLI%3EAz.sql%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sabrin_Alsahsah_3-1628685720043.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302358i4B874433D57B3A12%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Sabrin_Alsahsah_3-1628685720043.png%22%20alt%3D%22Sabrin_Alsahsah_3-1628685720043.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E4.%20Add%20one%20of%20the%20below%20PowerShell%20commands%20to%20your%20runbook%20based%20on%20your%20Azure%20SQL%20resource%20type%2C%20if%20its%20Azure%20SQL%20database%20or%20Azure%20SQL%20managed%20instance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3EAzure%20SQL%20database%20%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3ENotes%3A%20%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20below%20script%20will%20use%20%3CSTRONG%3EGeo%20Restore%3C%2FSTRONG%3E%20to%20retsore%20the%20database%20from%20one%20Azure%20SQL%20server%20to%20another%20Azure%20SQL%20server.%20Geo-restore%20is%20available%20only%20for%20SQL%20databases%20configured%20with%20geo-redundant%20backup%20storage%20and%20you%20can%20have%20more%20information%20by%20accessing%20this%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-sql%2Fdatabase%2Frecovery-using-backups%23geo-restore%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Elink%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3EThe%20script%20will%20include%20a%20%3CU%3Eremove%20database%20command%3C%2FU%3E%20as%20it%20will%20remove%20the%20existing%20database%20and%20restore%20a%20new%20copy.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3EYou%20can%20adjust%20the%20service%20tier%20level%20on%20the%20script%20as%20required.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EImport-Module%20Az.Accounts%0AImport-Module%20Az.Automation%0AImport-Module%20Az.Compute%0AImport-Module%20Az.sql%0A%0A%23%20Ensures%20you%20do%20not%20inherit%20an%20AzContext%20in%20your%20runbook%0ADisable-AzContextAutosave%20-Scope%20Process%0A%0A%24connection%20%3D%20Get-AutomationConnection%20-Name%20AzureRunAsConnection%0A%0Awhile(!(%24connectionResult)%20-and%20(%24logonAttempt%20-le%2010))%0A%7B%0A%20%20%20%20%24LogonAttempt%2B%2B%0A%20%20%20%20%23%20Logging%20in%20to%20Azure...%0A%20%20%20%20%24connectionResult%20%3D%20Connect-AzAccount%20%60%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-ServicePrincipal%20%60%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-Tenant%20%24connection.TenantID%20%60%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-ApplicationId%20%24connection.ApplicationID%20%60%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-CertificateThumbprint%20%24connection.CertificateThumbprint%0A%0A%20%20%20%20Start-Sleep%20-Seconds%2030%0A%7D%0A%0A%24subscriptionId%20%3D%20%22******%22%0A%24resourceGroupName%20%3D%20%22******%22%0A%24ServerName%20%3D%20%22******%22%0A%24TargetServerName%3D%20%22******%22%0A%24databaseName%20%3D%20%22******%22%0A%24targetDatabase%20%3D%20%22******%22%0A%0AGet-AzSubscription%20-SubscriptionId%20%24subscriptionId%0ASelect-AzSubscription%20-SubscriptionId%20%24subscriptionId%0A%0ARemove-AzSqlDatabase%20-ResourceGroupName%20%24resourceGroupName%20-ServerName%20%24TargetServerName%20-DatabaseName%20%24targetDatabase%20-Force%0A%0A%24GeoBackup%20%3D%20Get-AzSqlDatabaseGeoBackup%20-ResourceGroupName%20%24resourceGroupName%20-ServerName%20%24ServerName%20-DatabaseName%20%24databaseName%0A%0ARestore-AzSqlDatabase%20-FromGeoBackup%20-ResourceGroupName%20%24resourceGroupName%20-ServerName%20%24TargetServerName%20-TargetDatabaseName%20%24targetDatabase%20-ResourceId%20%24GeoBackup.ResourceID%20-Edition%20%22Standard%22%20-ServiceObjectiveName%20%22S2%22%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3EAzure%20SQL%20managed%20instance%20%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CU%3ENotes%3A%20%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20below%20script%20will%20use%20%3CSTRONG%3EPoint%20In%20Time%20Restore%20(PITR)%3C%2FSTRONG%3E%20to%20restore%20a%20copy%20of%20the%20database%20from%20one%20Azure%20SQL%20isnatnce%20to%20another%20Azure%20SQL%20insatnce.%20You%20can%20have%20more%20information%20by%20accessing%20this%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-sql%2Fmanaged-instance%2Fpoint-in-time-restore%3Ftabs%3Dazure-powershell%23restore-an-existing-database%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Elink%3C%2FA%3E.%3C%2FLI%3E%0A%3CLI%3EThe%20script%20will%20include%20a%20%3CU%3Eremove%20database%20command%3C%2FU%3E%20as%20it%20will%20remove%20the%20old%20copy%20and%20create%20a%20new%20one%20as%20a%20copy.%3C%2FLI%3E%0A%3CLI%3EThe%20script%20will%20retsore%20the%20database%20to%20before%2030%20minutes%2C%20this%20can%20be%20adjuested%20as%20requried.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3EYou%20can%20adjust%20the%20service%20tier%20level%20on%20the%20script%20as%20required.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EImport-Module%20Az.Accounts%0AImport-Module%20Az.Automation%0AImport-Module%20Az.Compute%0AImport-Module%20Az.sql%0A%24connectionName%20%3D%20%22AzureRunAsConnection%22%0Atry%0A%7B%0A%20%20%20%20%20%23%20Get%20the%20connection%20%22AzureRunAsConnection%20%22%0A%20%20%20%20%20%24servicePrincipalConnection%20%3D%20Get-AutomationConnection%20-Name%20%24connectionName%20%20%20%20%20%20%20%0A%22Logging%20in%20to%20Azure...%22%0AConnect-AzAccount%20%60%0A-ServicePrincipal%20%60%0A-TenantId%20%24servicePrincipalConnection.TenantId%20%60%0A-ApplicationId%20%24servicePrincipalConnection.ApplicationId%20%60%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20-CertificateThumbprint%20%24servicePrincipalConnection.CertificateThumbprint%20%0A%7D%0Acatch%20%7B%0A%20%20%20%20%20if%20(!%24servicePrincipalConnection)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%24ErrorMessage%20%3D%20%22Connection%20%24connectionName%20not%20found.%22%0A%20%20%20%20%20%20%20%20throw%20%24ErrorMessage%0A%20%20%20%20%20%20%20%7D%20else%7B%0A%20%20%20%20%20%20%20%20Write-Error%20-Message%20%24_.Exception%0A%20%20%20%20%20%20%20%20throw%20%24_.Exception%0A%20%20%20%20%20%20%20%7D%0A%7D%0A%20%0ASet-azContext%20-SubscriptionId%20%22********%22%0A%24targetResourceGroupName%20%3D%20%22********%22%0A%24targetInstanceName%20%3D%20%22********%22%0A%24targetDatabase%20%3D%20%22********%22%0A%24subscriptionId%20%3D%20%22********%22%0A%24resourceGroupName%20%3D%20%22********%22%0A%24managedInstanceName%20%3D%20%22********%22%0A%24databaseName%20%3D%20%22********%22%0A%24pointInTime%20%3D%20(Get-Date).AddMinutes(-30)%0ARemove-AzSqlInstanceDatabase%20-Name%20%24targetDatabase%20-InstanceName%20%24targetInstanceName%20-ResourceGroupName%20%24targetResourceGroupName%20%20-Force%0ARestore-AzSqlInstanceDatabase%20-FromPointInTimeBackup%20-ResourceGroupName%20%24resourceGroupName%20-InstanceName%20%24managedInstanceName%20-Name%20%24databaseName%20-PointInTime%20%24pointInTime%20-%20%20%20%20%20TargetInstanceDatabaseName%20%24targetDatabase%20-%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E5.%20Create%20a%20schedule%20for%20your%20runbook%20by%20following%20the%20steps%20in%20this%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fautomation%2Fshared-resources%2Fschedules%23create-a-new-schedule-in-the-azure-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Elink%3C%2FA%3E%2C%20and%20make%20sure%20to%20link%20it%20with%20your%20runbook.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sabrin_Alsahsah_4-1628686127817.png%22%20style%3D%22width%3A%20557px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302359i9017458F05392491%2Fimage-dimensions%2F557x160%3Fv%3Dv2%22%20width%3D%22557%22%20height%3D%22160%22%20role%3D%22button%22%20title%3D%22Sabrin_Alsahsah_4-1628686127817.png%22%20alt%3D%22Sabrin_Alsahsah_4-1628686127817.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E6.%20Test%20running%20the%20runbook%20and%20make%20sure%20you%20are%20not%20receiving%20any%20errors%20in%20the%20errors%20sections.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Sabrin_Alsahsah_5-1628686146950.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302360i4F4C262BBDF98E4C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Sabrin_Alsahsah_5-1628686146950.png%22%20alt%3D%22Sabrin_Alsahsah_5-1628686146950.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20hope%20this%20article%26nbsp%3Bwas%20helpful%20for%20you%2C%20please%20feel%20free%20to%20share%20your%20feedback%20in%20the%20comments%20section.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESabrin%20Alsahsah%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2636181%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20this%20article%2C%20we%20consider%20the%20scenario%20where%20customers%20would%20like%20to%20restore%20their%20Azure%20SQL%20database%20and%20managed%20database%20from%20one%20Azure%20SQL%20server%20to%20another%20Azure%20SQL%20server%2C%20for%20example%20for%20development%20reasons.%20The%20article%20will%20provide%20you%20with%20the%20steps%20to%20achieve%20this%20by%20automating%20the%20job%20using%20Azure%20Automation%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2636181%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Automation%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20SQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ecopy%20database%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Emaintenance%20plan%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ERestore%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%20Database%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%20Managed%20Instance%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2711411%22%20slang%3D%22en-US%22%3ERe%3A%20Restore%20database%20across%20servers(Azure%20SQL%20Database%20and%20Azure%20SQL%20managed%20instance)-%20Azure%20Automa%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2711411%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F699400%22%20target%3D%22_blank%22%3E%40Sabrin_Alsahsah%3C%2FA%3E%26nbsp%3BThanks%20for%20the%20article%2C%26nbsp%3B%20Is%20it%20possible%20to%20restore%20the%20DB%20across%20servers%20in%20different%20subscriptions%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Aug 12 2021 04:20 AM
Updated by: