Skip to content

Files

Latest commit

96a623c · Sep 21, 2018

History

History
55 lines (41 loc) · 2.84 KB

sql-database-copy-database-to-new-server-powershell.md

File metadata and controls

55 lines (41 loc) · 2.84 KB

title: PowerShell example-copy-Azure SQL database-new server | Microsoft Docs description: Azure PowerShell example script to copy a SQL database to a new server services: sql-database ms.service: sql-database ms.subservice: data-movement ms.custom: ms.devlang: PowerShell ms.topic: sample author: CarlRabeler ms.author: carlrab ms.reviewer: manager: craigg ms.date: 09/07/2018

Use PowerShell to copy a SQL database to a new server

This PowerShell script example creates a copy of an existing database in a new server.

[!INCLUDE quickstarts-free-trial-note] [!INCLUDE cloud-shell-powershell.md]

If you choose to install and use the PowerShell locally, this tutorial requires the Azure PowerShell module version 5.7.0 or later. Run Get-Module -ListAvailable AzureRM to find the version. If you need to upgrade, see Install Azure PowerShell module. If you are running PowerShell locally, you also need to run Connect-AzureRmAccount to create a connection with Azure.

Copy a database to a new server

[!code-powershell-interactivemain]

Clean up deployment

After the script sample has been run, the following command can be used to remove the resource group and all resources associated with it.

Remove-AzureRmResourceGroup -ResourceGroupName $sourceresourcegroupname
Remove-AzureRmResourceGroup -ResourceGroupName $targetresourcegroupname

Script explanation

This script uses the following commands. Each command in the table links to command specific documentation.

Command Notes
New-AzureRmResourceGroup Creates a resource group in which all resources are stored.
New-AzureRmSqlServer Creates a logical server that hosts a database or elastic pool.
New-AzureRmSqlDatabase Creates a database in a logical server as a single or a pooled database.
New-AzureRmSqlDatabaseCopy Creates a copy of a database that uses the snapshot at the current time.
Remove-AzureRmResourceGroup Deletes a resource group including all nested resources.

Next steps

For more information on the Azure PowerShell, see Azure PowerShell documentation.

Additional SQL Database PowerShell script samples can be found in the Azure SQL Database PowerShell scripts.