Author | Chrissy LeMaire (@cl), netnerds.net |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Invoke-DbaDbMirroring on GitHub.
Want to see the Bill Of Health for this command? Check out Invoke-DbaDbMirroring.
Automates the creation of database mirrors.
Automates the creation of database mirrors.
NOTE: If a backup / restore is performed, the backups will be left in tact on the network share.
Invoke-DbaDbMirroring
[[-Primary] <DbaInstanceParameter>]
[[-PrimarySqlCredential] <PSCredential>]
[-Mirror] <DbaInstanceParameter[]>
[[-MirrorSqlCredential] <PSCredential>]
[[-Witness] <DbaInstanceParameter>]
[[-WitnessSqlCredential] <PSCredential>]
[[-Database] <String[]>]
[[-EndpointEncryption] <String>]
[[-EncryptionAlgorithm] <String>]
[[-SharedPath] <String>]
[[-InputObject] <Database[]>]
[-UseLastBackup]
[-Force]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> $params = @{
>> Primary = 'sql2017a'
>> Mirror = 'sql2017b'
>> MirrorSqlCredential = 'sqladmin'
>> Witness = 'sql2019'
>> Database = 'pubs'
>> SharedPath = '\\nas\sql\share'
>> }
>>
PS C:\> Invoke-DbaDbMirroring @params
Performs a bunch of checks to ensure the pubs database on sql2017a
can be mirrored from sql2017a to sql2017b. Logs in to sql2019 and sql2017a
using Windows credentials and sql2017b using a SQL credential.
Prompts for confirmation for most changes. To avoid confirmation, use -Confirm:$false or
use the syntax in the second example.
PS C:\> $params = @{
>> Primary = 'sql2017a'
>> Mirror = 'sql2017b'
>> MirrorSqlCredential = 'sqladmin'
>> Witness = 'sql2019'
>> Database = 'pubs'
>> SharedPath = '\\nas\sql\share'
>> Force = $true
>> Confirm = $false
>> }
>>
PS C:\> Invoke-DbaDbMirroring @params
Performs a bunch of checks to ensure the pubs database on sql2017a
can be mirrored from sql2017a to sql2017b. Logs in to sql2019 and sql2017a
using Windows credentials and sql2017b using a SQL credential.
Drops existing pubs database on Mirror and restores it with
a fresh backup.
Does all the things in the description, does not prompt for confirmation.
PS C:\> $map = @{ 'database_data' = 'M:\Data\database_data.mdf' 'database_log' = 'L:\Log\database_log.ldf' }
PS C:\> Get-ChildItem \\nas\seed | Restore-DbaDatabase -SqlInstance sql2017b -FileMapping $map -NoRecovery
PS C:\> Get-DbaDatabase -SqlInstance sql2017a -Database pubs | Invoke-DbaDbMirroring -Mirror sql2017b -Confirm:$false
Restores backups from sql2017a to a specific file structure on sql2017b then creates mirror with no prompts for confirmation.
PS C:\> Get-DbaDatabase -SqlInstance sql2017a -Database pubs |
>> Invoke-DbaDbMirroring -Mirror sql2017b -UseLastBackup -Confirm:$false
Mirrors pubs on sql2017a to sql2017b and uses the last full and logs from sql2017a to seed. Doesn't prompt for confirmation.
SQL Server name or SMO object representing the mirror SQL Server.
Alias | |
Required | True |
Pipeline | false |
Default Value |
SQL Server name or SMO object representing the primary SQL Server.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
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 |
SQL Server name or SMO object representing the witness SQL Server.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
The database or databases to mirror.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Used to specify the state of encryption on the endpoint. Defaults to required.
Disabled
Required
Supported
Alias | |
Required | False |
Pipeline | false |
Default Value | Required |
Accepted Values | Disabled,Required,Supported |
Specifies an encryption algorithm used on an endpoint. Defaults to Aes.
Options are:
AesRC4
Aes
None
RC4
RC4Aes
Alias | |
Required | False |
Pipeline | false |
Default Value | Aes |
Accepted Values | Aes,AesRC4,None,RC4,RC4Aes |
The network share where the backups will be backed up and restored from.
Each SQL Server service account must have access to this share.
NOTE: If a backup / restore is performed, the backups will be left in tact on the network share.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Enables piping from Get-DbaDatabase.
Alias | |
Required | False |
Pipeline | true (ByValue) |
Default Value |
Use the last full backup of database.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Drop and recreate the database on remote servers using fresh backup.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
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 |
Shows what would happen if the command were to run. No actions are actually performed.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts you for confirmation before executing any changing operations within the command.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |