Purpose:
This article help you cancel ongoing import or export operation on Azure SQL Database.
Step by Step guidance:
function Cancel-AzSQLImportExportOperation
{
param
(
[parameter(Mandatory=$true)][string]$ResourceGroupName
,[parameter(Mandatory=$true)][string]$ServerName
,[parameter(Mandatory=$true)][string]$DatabaseName
)
$Operation = Get-AzSqlDatabaseActivity -ResourceGroupName $ResourceGroupName -ServerName $ServerName -DatabaseName $DatabaseName | Where-Object {($_.Operation -like "Export*" -or $_.Operation -like "Import*") -and $_.State -eq "InProgress"}
if(-not [string]::IsNullOrEmpty($Operation))
{
do
{
Write-Host -ForegroundColor Cyan ("Operation " + $Operation.Operation + " with OperationID: " + $Operation.OperationId + " is now " + $Operation.State)
$UserInput = Read-Host -Prompt "Should I cancel this operation? (Y/N)"
} while($UserInput -ne "Y" -and $UserInput -ne "N")
if($UserInput -eq "Y")
{
"Canceling operation"
Stop-AzSqlDatabaseActivity -ResourceGroupName $ResourceGroupName -ServerName $ServerName -DatabaseName $DatabaseName -OperationId $Operation.OperationId
}
else
{"Exiting without cenceling the operation"}
}
else
{
"No import or export operation is now running"
}
}
Cancel-AzSQLImportExportOperation
Cancel-AzSQLImportExportOperation
to cancel an Import or Export operation
I hope you find it useful.
Thank you Roshna Nazir for pointing out this functionality.
if you have any feedback please do not hesitate to provide it in a comment below.
Yochanan.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.