Total Page Preview:   000000006380

How to copy Azure SQL Database into the same Azure SQL Server using powershell command line

In this article I am going to explain How to copy Azure SQL Database into the same Azure SQL Server using powershell command line 

Copy Azure SQL Database into the same Azure SQL Server  powershell command with ARM Scripts:

#-------- TenantId -------------#

Get TenantId from the Azure Portal: 
Get TenantId In Azure
 
$tenantid = 'd29b7a9b-dddd-bbbb-vvvv-3c5c6c3eeeb0'
 
#----------Your UserId and Password--------------------#
$username =  'xxxxxxxxx@live.com'
$password = 'xxxxxxxxxxx' | ConvertTo-SecureString -asPlainText -Force
 
$cred = New-Object System.Management.Automation.PSCredential($username, $password)
Login-AzureRmAccount -TenantId $tenantid -Credential $cred
 
#------------------------If you have multiple subscriptionId in single account-----------#
$subscriptionId = (Get-AzureRmSubscription | Out-GridView -Title "Select an Azure Subscription …" -PassThru).SubscriptionId
 
#------------------------for single subscriptionId -----------#
$subscriptionId = (Get-AzureRmSubscription).SubscriptionId
 
#------------ Please enter already existing Resource group and Azure SQL Server Name -------------#
 
$rgroup = Read-Host -Prompt 'Enter Resource Group name'
$serverName = Read-Host -Prompt 'Please Enter Azure SQL Server Name' 
 
#---- Please enter Sourse Database name and copy database name  -----------#
$databaseName = Read-Host -Prompt 'Please Enter the sourse azure SQL Database Name'
$copyDatabaseName = Read-Host -Prompt 'Enter the Azure SQL Copy Database Name'
 
#--------------------------Copy Azure SQL Database into the same server-------------------------#
$NewCopyMsgdb = New-AzureRmSqlDatabaseCopy -ResourceGroupName $rgroup -CopyResourceGroupName $rgroup
 -ServerName $serverName -CopyServerName $serverName -DatabaseName $databaseName -CopyDatabaseName $copyDatabaseName 
 
 
if ($NewCopyMsgdb -eq $null)
{
    Write-Host "Database has not been copied successfully"
}
else 
{
    Write-Host "Database" $newcoptydb.DatabaseName "has been copied successfully"
}
 
Copy Azure SQL Database into the same Azure SQL Server  powershell command with ARM:
Copy Azure SQL Database Using Powershell
 
By Brijesh Kumar
Thanks 

 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments


                           
                           

                           

                           

Facebook User: