< Back

Restore-AzureRmSqlDatabase

Tue Jan 29, 2019 10:10 pm

NAME Restore-AzureRmSqlDatabase



SYNOPSIS

Restores a SQL database.





SYNTAX

Restore-AzureRmSqlDatabase [-ResourceGroupName] <String> [-AsJob] [-DefaultProfile <IAzureContextContainer>] -DeletionDate <DateTime> [-Edition

{None | Premium | Basic | Standard | DataWarehouse | Stretch | Free | PremiumRS}] [-ElasticPoolName <String>] -FromDeletedDatabaseBackup

[-PointInTime <DateTime>] -ResourceId <String> -ServerName <String> [-ServiceObjectiveName <String>] -TargetDatabaseName <String>

[<CommonParameters>]



Restore-AzureRmSqlDatabase [-ResourceGroupName] <String> [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-Edition {None | Premium | Basic |

Standard | DataWarehouse | Stretch | Free | PremiumRS}] [-ElasticPoolName <String>] -FromGeoBackup -ResourceId <String> -ServerName <String>

[-ServiceObjectiveName <String>] -TargetDatabaseName <String> [<CommonParameters>]



Restore-AzureRmSqlDatabase [-ResourceGroupName] <String> [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-Edition {None | Premium | Basic |

Standard | DataWarehouse | Stretch | Free | PremiumRS}] [-ElasticPoolName <String>] -FromLongTermRetentionBackup -ResourceId <String> -ServerName

<String> [-ServiceObjectiveName <String>] -TargetDatabaseName <String> [<CommonParameters>]



Restore-AzureRmSqlDatabase [-ResourceGroupName] <String> [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-Edition {None | Premium | Basic |

Standard | DataWarehouse | Stretch | Free | PremiumRS}] [-ElasticPoolName <String>] -FromPointInTimeBackup -PointInTime <DateTime> -ResourceId

<String> -ServerName <String> [-ServiceObjectiveName <String>] -TargetDatabaseName <String> [<CommonParameters>]





DESCRIPTION

The Restore-AzureRmSqlDatabase cmdlet restores a SQL database from a geo-redundant backup, a backup of a deleted database, a long term retention

backup, or a point in time in a live database. The restored database is created as a new database.



You can create an elastic SQL database by setting the ElasticPoolName parameter to an existing elastic pool.





PARAMETERS

-AsJob [<SwitchParameter>]

Run cmdlet in the background



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-DefaultProfile <IAzureContextContainer>

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



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-DeletionDate <DateTime>

Specifies the deletion date as a DateTime object. To get a DateTime object, use the Get-Date cmdlet.



Required? true

Position? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-Edition <DatabaseEdition>

Specifies the edition of the SQL database. The acceptable values for this parameter are:



- None



- Premium



- Basic



- Standard



- DataWarehouse



- Free



Required? false

Position? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-ElasticPoolName <String>

Specifies the name of the elastic pool in which to put the SQL database.



Required? false

Position? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-FromDeletedDatabaseBackup [<SwitchParameter>]

Indicates that this cmdlet restores a database from a backup of a deleted SQL database. You can use the Get-AzureRMSqlDeletedDatabaseBackup

cmdlet to get the backup of a deleted SQL database.



Required? true

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-FromGeoBackup [<SwitchParameter>]

Indicates that this cmdlet restores a SQL database from a geo-redundant backup. You can use the Get-AzureRMSqlDatabaseGeoBackup cmdlet to get

a geo-redundant backup.



Required? true

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-FromLongTermRetentionBackup [<SwitchParameter>]

Indicates that this cmdlet restores a SQL database from a long term retention backup.



Required? true

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-FromPointInTimeBackup [<SwitchParameter>]

Indicates that this cmdlet restores a SQL database from a point-in-time backup.



Required? true

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-PointInTime <DateTime>

Specifies the point in time, as a DateTime object, that you want to restore your SQL database to. To get a DateTime object, use Get-Date

cmdlet.



Use this parameter together with the FromPointInTimeBackup parameter.



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ResourceGroupName <String>

Specifies the name of the resource group to which this cmdlet assigns the SQL database.



Required? true

Position? 0

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-ResourceId <String>

Specifies the ID of the resource to restore.



Required? true

Position? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-ServerName <String>

Specifies the name of the SQL database server.



Required? true

Position? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-ServiceObjectiveName <String>

Specifies the name of the service objective.



Required? false

Position? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-TargetDatabaseName <String>

Specifies the name of the database to restore to.



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

None

This cmdlet does not accept any input.





OUTPUTS

Microsoft.Azure.Commands.Sql.Database.Model.AzureSqlDatabaseModel







NOTES









Example 1: Restore a database from a point in time



PS C:\\>$Database = Get-AzureRmSqlDatabase -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -DatabaseName "Database01"

PS C:\\> Restore-AzureRmSqlDatabase -FromPointInTimeBackup -PointInTime UTCDateTime -ResourceGroupName $Database.ResourceGroupName -ServerName

$Database.ServerName -TargetDatabaseName "RestoredDatabase" -ResourceId $Database.ResourceID -Edition "Standard" -ServiceObjectiveName "S2"



The first command gets the SQL database named Database01, and then stores it in the $Database variable.



The second command restores the database in $Database from the specified point-in-time backup to the database named RestoredDatabase.





Example 2: Restore a database from a point in time to an elastic pool



PS C:\\>$Database = Get-AzureRmSqlDatabase -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -DatabaseName "Database01"

PS C:\\> Restore-AzureRmSqlDatabase -FromPointInTimeBackup -PointInTime UTCDateTime -ResourceGroupName $Database.ResourceGroupName -ServerName

$Database.ServerName -TargetDatabaseName "RestoredDatabase" -ResourceId $Database.ResourceID -ElasticPoolName "ElasticPool01"



The first command gets the SQL database named Database01, and then stores it in the $Database variable.



The second command restores the database in $Database from the specified point-in-time backup to the SQL database named RestoredDatabase in the

elastic pool named elasticpool01.





Example 3: Restore a deleted database



PS C:\\>$DeletedDatabase = Get-AzureRmSqlDeletedDatabaseBackup -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -DatabaseName

"Database01"

PS C:\\> Restore-AzureRmSqlDatabase -FromDeletedDatabaseBackup -DeletionDate $DeletedDatabase.DeletionDate -ResourceGroupName

$DeletedDatabase.ResourceGroupName -ServerName $DeletedDatabase.ServerName -TargetDatabaseName "RestoredDatabase" -ResourceId

$DeletedDatabase.ResourceID -Edition "Standard" -ServiceObjectiveName "S2" -PointInTime UTCDateTime



The first command gets the deleted database backup that you want to restore by using Get-AzureRmSqlDeletedDatabaseBackup

(./Get-AzureRMSqlDeletedDatabaseBackup.md). The second command starts the restore from the deleted database backup by using the

Restore-AzureRmSqlDatabase (./Restore-AzureRmSqlDatabase.md)cmdlet. If the -PointInTime parameter is not specified, the database will be restored

to the deletion time.





Example 4: Restore a deleted database into an elastic pool



PS C:\\>$DeletedDatabase = Get-AzureRmSqlDeletedDatabaseBackup -ResourceGroupName $resourceGroupName -ServerName $sqlServerName -DatabaseName

'DatabaseToRestore'

PS C:\\> Restore-AzureRmSqlDatabase -FromDeletedDatabaseBackup -DeletionDate $DeletedDatabase.DeletionDate -ResourceGroupName

$DeletedDatabase.ResourceGroupName -ServerName $DeletedDatabase.ServerName -TargetDatabaseName "RestoredDatabase" -ResourceId

$DeletedDatabase.ResourceID -ElasticPoolName "elasticpool01" -PointInTime UTCDateTime



The first command gets the deleted database backup that you want to restore by using Get-AzureRmSqlDeletedDatabaseBackup

(./Get-AzureRMSqlDeletedDatabaseBackup.md). The second command starts the restore from the deleted database backup by using

Restore-AzureRmSqlDatabase (./Restore-AzureRmSqlDatabase.md). If the -PointInTime parameter is not specified, the database will be restored to the

deletion time.





Example 5: Geo-Restore a database



PS C:\\>$GeoBackup = Get-AzureRmSqlDatabaseGeoBackup -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -DatabaseName "Database01"

PS C:\\> Restore-AzureRmSqlDatabase -FromGeoBackup -ResourceGroupName "TargetResourceGroup" -ServerName "TargetServer" -TargetDatabaseName

"RestoredDatabase" -ResourceId $GeoBackup.ResourceID -Edition "Standard" -RequestedServiceObjectiveName "S2"



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 SQL database named RestoredDatabase.







RELATED LINKS

Online Version: https://docs.microsoft.com/en-us/powers ... qldatabase

Recover an Azure SQL Database from an outage http://go.microsoft.com/fwlink/?LinkId=746882

Recover an Azure SQL Database from a user error http://go.microsoft.com/fwlink/?LinkId=746944

Get-AzureRmSqlDatabaseBackupLongTermRetentionPolicy

Get-AzureRmSqlDatabaseGeoBackup

Get-AzureRmSqlDeletedDatabaseBackup

SQL Database Documentation https://docs.microsoft.com/azure/sql-database/