Search code examples
databaseazurecopyazure-sql-databasetransfer

Copy Database Data on Azure into Another Database on Azure


We have two sql databases, test and production, hosted on Microsoft Azure. Both databases have the same schema. Is there an automated or one-click way to copy all of the data from the production database into the test database. Whenever we make a new feature we want to be able to test it with up-to-date production data without testing it on the production database.

Any amount of initial setup is fine, but ideally the end result would be to essentially hit a button and the copy is done.

It is OK if the test database needs to be wiped beforehand.

If there is no way to do this on Azure, what would the next best option be to get this result?


Solution

  • You just need to copy the database using the portal or PowerShell

    New-AzureRmSqlDatabaseCopy -ResourceGroupName "myResourceGroup" `
        -ServerName $sourceserver `
        -DatabaseName "MySampleDatabase" `
        -CopyResourceGroupName "myResourceGroup" `
        -CopyServerName $targetserver `
        -CopyDatabaseName "CopyOfMySampleDatabase"
    

    You can also automate refreshing the development database by recreating it using Azure Automation and the following T-SQL statement.

    CREATE DATABASE db_copy   
        AS COPY OF ozabzw7545.db_original ( SERVICE_OBJECTIVE = 'P2' );