'The sku 'ElasticPool' specified is invalid' with New-AzSqlDatabaseCopy - azure

I'm trying to convert from New-AzureRmSqlDatabaseCopy to New-AzSqlDatabaseCopy, but I'm getting an error when trying to copy a database to the same server:
Microsoft.Rest.Azure.CloudException: Long running operation failed
with status 'Failed'. Additional Info:'The sku 'ElasticPool' specified
is invalid.'
New-AzSqlDatabaseCopy `
-ResourceGroupName $resourceGroupName `
-ServerName $serverName `
-DatabaseName $templateDbName `
-CopyDatabaseName $newDbName `
-CopyServerName $serverName `
-CopyResourceGroupName $resourceGroupName
The database copies successfully when using New-AzureRmSqlDatabaseCopy, I can't figure why New-AzSqlDatabaseCopy would be different. I've tried specifying the -ElasticPoolName and -ServiceObjectName parameters, but no luck.
I don't know if this is relevant, but I'm running the PowerShell from an Azure runbook.

Make sure that the new Elastic Pool has the same name and as the old Elastic Pool. Also make sure the SKU are same for both the elastic pools. If the resource groups are in different regions, the SKU (Standard?) for elastic pools may differ causing issues while copying the database.

Related

Move Azure Synapse DB Between Servers

I have 2 SQL servers under the same subscription in azure, both have an azure synapse DB on them. I want to move/copy one of the synapse DB's to the other server. I cannot find any documentation to do this online, all the stuff I have found refers to a normal SQL DB and the copy TSQL or the method doesn't seem to work. Can anyone refer me to an article explaining how I do this, or explain how I do this in azure?
Kind Regards
Glyn
The simplest way to do this is going to be through restore points, similar to how you might do it with a backup file in SQL Server. You can create a restore point either in the portal or via Powershell.
$SubscriptionName="<YourSubscriptionName>"
$ResourceGroupName="<YourResourceGroupName>"
$ServerName="<YourServerNameWithoutURLSuffixSeeNote>" # Without database.windows.net
$DatabaseName="<YourDatabaseName>"
$Label = "<YourRestorePointLabel>"
Connect-AzAccount
Get-AzSubscription
Select-AzSubscription -SubscriptionName $SubscriptionName
# Create a restore point of the original database
New-AzSqlDatabaseRestorePoint -ResourceGroupName $ResourceGroupName -ServerName $ServerName -DatabaseName $DatabaseName -RestorePointLabel $Label
Once the point is created it is possible to restore it to a different server, again using the portal or via Powershell script. They don't need to be in the same resource group for this to work.
$SubscriptionName="<YourSubscriptionName>"
$ResourceGroupName="<YourResourceGroupName>"
$ServerName="<YourServerNameWithoutURLSuffixSeeNote>" # Without database.windows.net
#$TargetResourceGroupName="<YourTargetResourceGroupName>" # uncomment to restore to a different server.
#$TargetServerName="<YourtargetServerNameWithoutURLSuffixSeeNote>"
$DatabaseName="<YourDatabaseName>"
$NewDatabaseName="<YourDatabaseName>"
Connect-AzAccount
Get-AzSubscription
Select-AzSubscription -SubscriptionName $SubscriptionName
# Or list all restore points
Get-AzSqlDatabaseRestorePoint -ResourceGroupName $ResourceGroupName -ServerName $ServerName -DatabaseName $DatabaseName
# Get the specific database to restore
$Database = Get-AzSqlDatabase -ResourceGroupName $ResourceGroupName -ServerName $ServerName -DatabaseName $DatabaseName
# Pick desired restore point using RestorePointCreationDate "xx/xx/xxxx xx:xx:xx xx"
$PointInTime="<RestorePointCreationDate>"
# Restore database from a restore point
$RestoredDatabase = Restore-AzSqlDatabase –FromPointInTimeBackup –PointInTime $PointInTime -ResourceGroupName $Database.ResourceGroupName -ServerName $Database.ServerName -TargetDatabaseName $NewDatabaseName –ResourceId $Database.ResourceID
# Use the following command to restore to a different server
#$TargetResourceGroupName = $Database.ResourceGroupName # for restoring to different server in same resourcegroup
#$RestoredDatabase = Restore-AzSqlDatabase –FromPointInTimeBackup –PointInTime $PointInTime -ResourceGroupName $TargetResourceGroupName -ServerName $TargetServerName -TargetDatabaseName $NewDatabaseName –ResourceId $Database.ResourceID
# Verify the status of restored database
$RestoredDatabase.status
This doesn't cover things like server firewall settings, so if you want those to match you'll have to move that separately. The server is Azure SQL, so guides for migrating Azure SQL firewalls should also apply to Synapse dedicated pools.
If the number of tables is small, then the copy activity in Pipelines might be a good backup option, but since it requires one activity per table, setting it up for a large database will be significantly more complex than using restore points.

Check whether Azure SQL database has been fully removed

I am creating a simple Azure logic app that uses a function to:
Delete a slave database
Restore a copy of a master database (with the same name as the removed slave)
Remove Database
# Remove slave database
Remove-AzSqlDatabase `
-DatabaseName $RestoreDatabaseName `
-ServerName $ServerName `
-ResourceGroupName $ResourceGroupName
Write-Host "Removed slave database"
Restore PIT Backup of Master
# Restore database
Restore-AzSqlDatabase `
-FromPointInTimeBackup `
-PointInTime (Get-Date).AddMinutes(-2) `
-ResourceGroupName $ResourceGroupName `
-ServerName $ServerName `
-TargetDatabaseName $RestoreDatabaseName `
-ResourceId $Database.ResourceID `
-ElasticPoolName $ElasticPoolName
The issue i am having is that after removing the database, Azure still sees the database on the server and so i get the following error when restoring:
The destination database name 'Slave' already exists on the server
'server address'.
I cant find any way to check if this has been fully removed before starting the next function. Any help on how to achieve this would be greatly appreciated.
You can use Get-AzSqlDatabase to check if the DB is still in play.
Get-AzSqlDatabase -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -DatabaseName "Database02"
Placing this in a loop with a sleep will give you a poll to check when the DB is finally gone for good and you can then resume your processing.
Start-Sleep -s 15
Make sure you have a circuit breaker in your logic to prevent and endless loop in the case of a failed deletion.
It may be easier to restore your DB with a new name to avoid the delay e.g. MyDb<yyyymmdd>
Or alternatively, use the Azure REST API from SQL DB delete.
DELETE https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/servers/testsvr/databases/testdb?api-version=2017-10-01-preview
and monitor the location response of the 204 Accepted to determine when the database has been completely removed. Azure Durable Functions give you a great monitor pattern you can use.

Clone azure SQL elastic database to non-elastic server in a different resource group

I'm trying to clone an existing Azure SQL DB that's in an elastic pool to a standard SQL server in a different resource group. Whenever I run (with Az Powershell)
Restore-AzSqlDatabase -FromPointInTimeBackup -PointInTime (Get-Date) -ResourceGroupName $TargetRGName -ServerName $TargetServerName -TargetDatabaseName $TargetDBName -ResourceId $Database.ResourceID,
I get the error Long running operation failed with status 'Failed'. Additional Info:'An unexpected error occured while processing the request.
According to my script, you use Point-in-time restoration to restore your database. But we can not use the way to restore a database on the different servers. For more details, please refer to https://learn.microsoft.com/en-us/azure/sql-database/sql-database-recovery-using-backups#point-in-time-restore.
So if you want to restore the database on the different server, I suggest you use geo-store. If we use it, we can restore a SQL database on any server in any Azure region from the most recent geo-replicated backups. For further information, you read the official document. Regarding how to implement it by powershell, please refer to the following script
Connect-AzAccount
# get geo backup
$GeoBackup = Get-AzSqlDatabaseGeoBackup -ResourceGroupName "ResourceGroup01" -ServerName "Server01" -DatabaseName "Database01"
#restore database
Restore-AzSqlDatabase -FromGeoBackup -ResourceGroupName "TargetResourceGroup" -ServerName "TargetServer" -TargetDatabaseName "RestoredDatabase" -ResourceId $GeoBackup.ResourceID -Edition "Standard" -RequestedServiceObjectiveName "S2"

Long running operation failed with status 'Failed'. Additional Info:'The sku 'ElasticPool' specified is invalid.'

I'm trying to clone an Azure SQL Database using the PSCmdlet New-AzSqlDatabaseCopy (after being told that Restore-AzSqlDatabase won't let me do cross-server copies). My command is as follows:
New-AzSqlDatabaseCopy -ServerName $SourceDatabase.ServerName `
-ResourceGroupName $SourceDatabase.ResourceGroupName `
-DatabaseName $SourceDatabase.DatabaseName `
-ServiceObjectiveName $SourceDatabase.CurrentServiceObjectiveName `
-CopyServerName $TargetServerName `
-CopyResourceGroupName $TargetResourceGroupName `
-CopyDatabaseName $TargetDBName `
-ElasticPoolName $ElasticPoolName`
-ErrorAction stop
The source database is in a different server and resource group than the target, and in a different elastic pool than the target will be.
I've checked and double-checked all of my parameters to make sure they are correct, and I ran it with -whatif and everything looks good (except the creation date is 1/1/0001 but i'm not super concerned about that yet)
However, when I run the command, I get New-AzSqlDatabaseCopy : Long running operation failed with status 'Failed'. Additional Info:'The sku 'ElasticPool' specified is invalid.' Any input would be appreciated
Make sure that the new Elastic Pool has the same name and as the old Elastic Pool. Also make sure the sku are same for both the elastic pools. If the resource groups are in different regions, the sku for elastic pools may differ causing issues while copying the database.
SQL server - sql_server_A
--- Elastic Pool - elastic_pool_1
----- database - template_db
SQL server - sql_server_B
--- Elastic Pool - elastic_pool_1 (name equal to Elastic Pool from sql_server_A)
References:
https://github.com/Azure/azure-libraries-for-net/issues/41
https://learn.microsoft.com/en-us/azure/sql-database/scripts/sql-database-move-database-between-pools-powershell
https://learn.microsoft.com/en-us/rest/api/sql/databases/createorupdate
https://learn.microsoft.com/en-us/rest/api/sql/elasticpools/createorupdate
Remove the "-ServiceObjectiveName" parameter. Only -elasticpool OR -ServiceObjectiveName can be used.

Azure SQL elastic pool not found for server

A few days ago, I have a problem with SQL elastic pool in Azure.
I have an application that copies a database that is in a SQL Elastic pool, after a few days in production, started to return the message:
{"code":"40857","message":"Elastic pool not found for server: 'XXX', elastic pool name: 'XXX'."}
I tried to make the copy by the web admin panel without success as well.
Get error log:
"properties": {
"statusMessage": "{\"status\":\"Failed\",\"error\":{\"code\":\"ResourceOperationFailure\",\"message\":\"The resource operation completed with terminal provisioning state 'Failed'.\",\"details\":[{\"code\":\"40857\",\"message\":\"Elastic pool not found for server: 'XXX', elastic pool name: 'XXX'.\"}]}}",
"statusCode": "Accepted",
"serviceRequestId": "XXX"
}
I have checked all the information, and they are correct! It was working and stopped.
Help me please
Let me provide you workarounds since I do not know why it stopped working. Please try using PowerShell as a workaround.
New-AzureRmSqlDatabaseCopy
-ResourceGroupName “source”
-ServerName “source”
-DatabaseName “source”
-CopyResourceGroupName “target”
-CopyServerName “target”
-CopyDatabaseName “target”
-ElasticPoolName “target”
Try specifying the -ElasticPoolName and without that parameter.
If the above does not work, move the database into a standalone performance level then copy it.
Set-AzureRmSqlDatabase -ResourceGroupName $resourcegroupname `
-ServerName $servername `
-DatabaseName $firstdatabasename `
-RequestedServiceObjectiveName "S0"

Resources