commands

^

Invoke-DbaDbClone

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Invoke-DbaDbClone on GitHub.
Want to see the Bill Of Health for this command? Check out Invoke-DbaDbClone.

Synopsis

Clones a database schema and statistics

Description

Clones a database schema and statistics.

This can be useful for testing query performance without requiring all the space needed for the data in the database.

Read more:
- https://sqlperformance.com/2016/08/sql-statistics/expanding-dbcc-clonedatabase
- https://support.microsoft.com/en-us/help/3177838/how-to-use-dbcc-clonedatabase-to-generate-a-schema-and-statistics-only

Thanks to Microsoft Tiger Team for the code and idea https://github.com/Microsoft/tigertoolbox/

Syntax

Invoke-DbaDbClone
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-InputObject] <Database[]>]
    [[-CloneDatabase] <String[]>]
    [-ExcludeStatistics]
    [-ExcludeQueryStore]
    [-UpdateStatistics]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Invoke-DbaDbClone -SqlInstance sql2016 -Database mydb -CloneDatabase myclone

Clones mydb to myclone on sql2016

Example: 2
PS C:\> Get-DbaDatabase -SqlInstance sql2016 -Database mydb | Invoke-DbaDbClone -CloneDatabase myclone, myclone2 -UpdateStatistics

Updates the statistics of mydb then clones to myclone and myclone2

Optional Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required False
Pipeline false
Default Value
-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-Database

The database to clone - this list is auto-populated from the server.

Alias
Required False
Pipeline false
Default Value
-InputObject

Enables piping from Get-DbaDatabase

Alias
Required False
Pipeline true (ByValue)
Default Value
-CloneDatabase

The name(s) to clone to.

Alias
Required False
Pipeline false
Default Value
-ExcludeStatistics

Exclude the statistics in the cloned database

Alias
Required False
Pipeline false
Default Value False
-ExcludeQueryStore

Exclude the QueryStore data in the cloned database

Alias
Required False
Pipeline false
Default Value False
-UpdateStatistics

Update the statistics prior to cloning (per Microsoft Tiger Team formula)

Alias
Required False
Pipeline false
Default Value False
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

Alias cf
Required False
Pipeline false
Default Value