How to refresh development and test databases.
Date created: May 31, 2018.
An easy way to refresh your development and test Azure SQL databases with the
production Azure SQL database is to copy or clone the production database.
Copying is an option if you do not need to exclude (big) tables related logs or
auditing from the production database.
To copy a production database you can use the
Azure portal or PowerShell.
New-AzureRmSqlDatabaseCopy -ResourceGroupName "myResourceGroup" `
-ServerName $sourceserver `
-DatabaseName "MySampleDatabase" `
-CopyResourceGroupName "myResourceGroup" `
-CopyServerName $targetserver `
-CopyDatabaseName "CopyOfMySampleDatabase"
The PowerShell option give you the ability to involve
Azure Automation to automate the process.
You can also automate refreshing the development database by recreating it using
Azure Automation with PowerShell and the following CREATE DATABASE AS COPY OF
T-SQL statement.
CREATE DATABASE db_copy
AS COPY OF ozabzw7545.db_original ( SERVICE_OBJECTIVE = 'P2' );
If you would like to know the progress of a copy database operation, you can use
below statement.
Select
[sys].[databases].[name],
[sys].[databases].[state_desc],
[sys].[dm_database_copies].[start_date],
[sys].[dm_database_copies].[modify_date],
[sys].[dm_database_copies].percent_complete],
[sys].[dm_database_copies].[error_code],
[sys].[dm_database_copies].[error_desc],
[sys].[dm_database_copies].[error_severity],
[sys].[dm_database_copies].[error_state]
From [sys].[databases] Left Outer Join
[sys].[dm_database_copies]
On [sys].[databases].[database_id] =
[sys].[dm_database_copies].[database_id]
Where [sys].[databases].[name] = 'mydatabase'