Redigera

Dela via


Restore-AzSqlInstanceDatabase

Restores an Azure SQL Managed Instance database.

Syntax

Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-SubscriptionId <String>]
       [-ResourceGroupName] <String>
       [-InstanceName] <String>
       [-Name] <String>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-InputObject] <AzureSqlManagedDatabaseBaseModel>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-ResourceId] <String>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-SubscriptionId <String>]
       [-ResourceGroupName] <String>
       [-InstanceName] <String>
       [-Name] <String>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-InputObject] <AzureSqlManagedDatabaseBaseModel>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-ResourceId] <String>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-SubscriptionId <String>]
       [-ResourceGroupName] <String>
       [-InstanceName] <String>
       [-Name] <String>
       [-DeletionDate] <DateTime>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-SubscriptionId <String>]
       [-ResourceGroupName] <String>
       [-InstanceName] <String>
       [-Name] <String>
       [-DeletionDate] <DateTime>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       -SubscriptionId <String>
       [-ResourceGroupName] <String>
       [-InstanceName] <String>
       [-Name] <String>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       -TargetSubscriptionId <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-InputObject] <AzureSqlManagedDatabaseBaseModel>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       -TargetSubscriptionId <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       [-ResourceId] <String>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       -TargetSubscriptionId <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromPointInTimeBackup]
       -SubscriptionId <String>
       [-ResourceGroupName] <String>
       [-InstanceName] <String>
       [-Name] <String>
       [-DeletionDate] <DateTime>
       -PointInTime <DateTime>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       -TargetSubscriptionId <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromGeoBackup]
       [-GeoBackupObject] <AzureSqlRecoverableManagedDatabaseModel>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromGeoBackup]
       [-ResourceId] <String>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromGeoBackup]
       [-ResourceGroupName] <String>
       [-InstanceName] <String>
       [-Name] <String>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Restore-AzSqlInstanceDatabase
       [-FromLongTermRetentionBackup]
       [-SubscriptionId <String>]
       [-ResourceId] <String>
       -TargetInstanceDatabaseName <String>
       -TargetInstanceName <String>
       -TargetResourceGroupName <String>
       [-AsJob]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]

Description

The Restore-AzSqlInstanceDatabase cmdlet restores an instance database from a geo-redundant backup, a point in time in a live database, or a long term retention backup. The restored database is created as a new instance database.

Examples

Example 1: Restore an instance database from a point in time

Restore-AzSqlInstanceDatabase -Name "Database01" -InstanceName "managedInstance1" -ResourceGroupName "ResourceGroup01" -PointInTime UTCDateTime -TargetInstanceDatabaseName "Database01_restored"

The command restores the instance database Database01 from the specified point-in-time backup to the instance database named Database01_restored.

Example 2: Restore an instance database from a point in time to another instance on different resource group

Restore-AzSqlInstanceDatabase -Name "Database01" -InstanceName "managedInstance1" -ResourceGroupName "ResourceGroup01" -PointInTime UTCDateTime -TargetInstanceDatabaseName "Database01_restored" -TargetInstanceName "managedInstance1" -TargetResourceGroupName "ResourceGroup02"

The command restores the instance database Database01 on instance managedInstance1 on resource group ResourceGroup01 from the specified point-in-time backup to the instance database named Database01_restored on instance managedInstance2 on resource group ResourceGroup02.

Example 3: Geo-Restore an instance database

$GeoBackup = Get-AzSqlInstanceDatabaseGeoBackup -ResourceGroupName "ResourceGroup01" -InstanceName "managedInstance1" -Name "Database01"
$GeoBackup | Restore-AzSqlInstanceDatabase -FromGeoBackup -TargetInstanceDatabaseName "Database01_restored" -TargetInstanceName "managedInstance2" -TargetResourceGroupName "ResourceGroup02"

The first command gets the geo-redundant backup for the database named Database01, and then stores it in the $GeoBackup variable. The second command restores the backup in $GeoBackup to the instance database named Database01_restored.

Example 4: Restore a deleted instance database from a point in time

$deletedDatabase = Get-AzSqlDeletedInstanceDatabaseBackup -ResourceGroupName "ResourceGroup01" -InstanceName "managedInstance1" -DatabaseName "DB1"
Restore-AzSqlInstanceDatabase -FromPointInTimeBackup -Name $deletedDatabase.Name -InstanceName $deletedDatabase.ManagedInstanceName -ResourceGroupName $deletedDatabase.ResourceGroupName -DeletionDate $deletedDatabase.DeletionDate -PointInTime UTCDateTime -TargetInstanceDatabaseName "Database01_restored"

The first command gets the deleted instance databases named 'DB1' on Instance 'managedInstance1'. The second command restores the fetched database, from the specified point-in-time backup to the instance database named Database01_restored.

Example 5: Restore a deleted instance database from a point in time

$deletedDatabase = Get-AzSqlDeletedInstanceDatabaseBackup -ResourceGroupName "ResourceGroup01" -InstanceName "managedInstance1" -DatabaseName "DB1"
Restore-AzSqlInstanceDatabase -FromPointInTimeBackup -InputObject $deletedDatabase[0] -PointInTime UTCDateTime -TargetInstanceDatabaseName "Database01_restored"

The first command gets the deleted instance databases named 'DB1' on Instance 'managedInstance1'. The second command restores the fetched database, from the specified point-in-time backup to the instance database named Database01_restored using input object.

Example 6: Restore a database from LTR backup.

Restore-AzSqlInstanceDatabase -FromLongTermRetentionBackup -ResourceId "/subscriptions/f46521f3-5bb0-4eea-a3c2-c2d5987df96b/resourceGroups/testResourceGroup/providers/Microsoft.Sql/locations/southeastasia/longTermRetentionManagedInstances/testInstance/longTermRetentionDatabases/test/longTermRetentionManagedInstanceBackups/15be823c-7e2c-49d8-819f-a3fdcad92215;132268250550000000" -TargetInstanceDatabaseName "restoreTarget" -TargetInstanceName "testInstance" -TargetResourceGroupName "testResourceGroup"

Location                          : southeastasia
Tags                              :
Collation                         : SQL_Latin1_General_CP1_CI_AS
Status                            : Online
RestorePointInTime                :
DefaultSecondaryLocation          : northeurope
CatalogCollation                  :
CreateMode                        :
StorageContainerUri               :
StorageContainerSasToken          :
SourceDatabaseId                  :
FailoverGroupId                   :
RecoverableDatabaseId             :
RestorableDroppedDatabaseId       :
LongTermRetentionBackupResourceId :
ResourceGroupName                 : testResourceGroup
ManagedInstanceName               : testInstance
Name                              : restoreTarget
CreationDate                      : 3/4/2020 8:12:56 AM
EarliestRestorePoint              : 3/4/2020 8:14:29 AM
Id                                : /subscriptions/f46521f3-5bb0-4eea-a3c2-c2d5987df96b/resourceGroups/testResourceGroup/providers/Microsoft.Sql/managedInstances/testInstance/databases/restoreTarget

Restores LTR backup with the given resource ID (which can be found by running Get-AzSqlInstanceDatabaseLongTermRetentionBackup).

Example 7. Restore database from different subscription

Restore-AzSqlInstanceDatabase -FromPointInTimeBackup `
			-SubscriptionId "sourceSubscriptionID" `
			-ResourceGroupName "sourceRGName" `
			-InstanceName "sourceManagedInstanceName" `
			-Name "sourceDatabaseName" `
			-PointInTime $pointInTime `
			-TargetInstanceDatabaseName "targetDatabaseName" `
			-TargetInstanceName "targetManagedInstnaceName" `
			-TargetResourceGroupName "targetResourceGroupName" `
			-TargetSubscriptionId "targetSubscriptionId"

The command restores database backup from instance in one subscription to database targetDatabaseName on instance targetManagedInstanceName to different subscription targetSubscriptionId.

Example 8. Restore database from different subscription using source object and pipping

Set-AzContext -SubscriptionId "sourceSubscriptionId"
$sourceDatabase = Get-AzSqlInstanceDatabase -Name "sourceDatabaseName" -InstanceName "sourceManagedInstanceName" -ResourceGroupName "sourceRGName"

Set-AzContext -SubscriptionId "targetSubscriptionId"
$sourceDatabase | Restore-AzSqlInstanceDatabase -FromPointInTimeBackup `
			-PointInTime $pointInTime `
			-TargetInstanceDatabaseName "targetDatabaseName" `
			-TargetInstanceName "targetManagedInstnaceName" `
			-TargetResourceGroupName "targetResourceGroupName" `
			-TargetSubscriptionId "targetSubscriptionId"

First command gets source managed database object and stores in variable sourceDatabase. Second command executes restore from source to the given target database using point in time restore.

Parameters

-AsJob

Run cmdlet in the background

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DeletionDate

The deletion date of deleted database.

Type:DateTime
Position:3
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-FromGeoBackup

Restore from a geo backup.

Type:SwitchParameter
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-FromLongTermRetentionBackup

Restore from a Long Term Retention backup.

Type:SwitchParameter
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-FromPointInTimeBackup

Restore from a point-in-time backup.

Type:SwitchParameter
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-GeoBackupObject

The recoverable instance database object to restore

Type:AzureSqlRecoverableManagedDatabaseModel
Aliases:RecoverableInstanceDatabase
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-InputObject

The Instance Database object to restore

Type:AzureSqlManagedDatabaseBaseModel
Aliases:InstanceDatabase
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-InstanceName

The instance name.

Type:String
Aliases:SourceInstanceName
Position:1
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Name

The instance database name to restore.

Type:String
Aliases:InstanceDatabaseName, SourceInstanceDatabaseName
Position:2
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-PointInTime

The point in time to restore the database to.

Type:DateTime
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-ResourceGroupName

The name of the resource group.

Type:String
Aliases:SourceResourceGroupName
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-ResourceId

The resource id of Instance Database object to restore

Type:String
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-SubscriptionId

Source subscription id.

Type:String
Aliases:SourceSubscriptionId
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-TargetInstanceDatabaseName

The name of the target instance database to restore to.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-TargetInstanceName

The name of the target instance to restore to. If not specified, the target instance is the same as the source instance.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-TargetResourceGroupName

The name of the target resource group to restore to. If not specified, the target resource group is the same as the source resource group.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-TargetSubscriptionId

The name of the target subscription id to restore to.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

AzureSqlManagedDatabaseBaseModel

AzureSqlRecoverableManagedDatabaseModel

String

Outputs

AzureSqlManagedDatabaseModel