commands

^

Invoke-DbaDbLogShipRecovery

Author Sander Stad (@sqlstad), sqlstad.nl
Availability Windows, Linux, macOS

 

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

Synopsis

Invoke-DbaDbLogShipRecovery recovers log shipped databases to a normal state to act upon a migration or disaster.

Description

By default all the databases for a particular instance are recovered.
If the database is in the right state, either standby or recovering, the process will try to recover the database.

At first the function will check if the backup source directory can still be reached.
If so it will look up the last transaction log backup for the database. If that backup file is not the last copied file the log shipping copy job will be started.
If the directory cannot be reached for the function will continue to the restoring process.
After the copy job check is performed the job is disabled to prevent the job to run.

For the restore the log shipping status is checked in the msdb database.
If the last restored file is not the same as the last file name found, the log shipping restore job will be executed.
After the restore job check is performed the job is disabled to prevent the job to run

The last part is to set the database online by restoring the databases with recovery

Syntax

Invoke-DbaDbLogShipRecovery
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-Database] <String[]>]
    [[-SqlCredential] <PSCredential>]
    [-NoRecovery]
    [-EnableException]
    [-Force]
    [[-InputObject] <Database[]>]
    [[-Delay] <Int32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Invoke-DbaDbLogShipRecovery -SqlInstance server1 -Force

Recovers all the databases on the instance that are enabled for log shipping

Example: 2
PS C:\> Invoke-DbaDbLogShipRecovery -SqlInstance server1 -SqlCredential $cred -Verbose -Force

Recovers all the databases on the instance that are enabled for log shipping using a credential

Example: 3
PS C:\> Invoke-DbaDbLogShipRecovery -SqlInstance server1 -database db_logship -Verbose

Recovers the database "db_logship" to a normal status

Example: 4
PS C:\> db1, db2, db3, db4 | Invoke-DbaDbLogShipRecovery -SqlInstance server1 -Verbose

Recovers the database db1, db2, db3, db4 to a normal status

Example: 5
PS C:\> Invoke-DbaDbLogShipRecovery -SqlInstance server1 -Force -WhatIf

Shows what would happen if the command were executed.

Optional Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required False
Pipeline false
Default Value
-Database

Database to perform the restore for. This value can also be piped enabling multiple databases to be recovered.
If this value is not supplied all databases will be recovered.

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
-NoRecovery

Allows you to choose to not restore the database to a functional state (Normal) in the final steps of the process.
By default the database is restored to a functional state (Normal).

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
-Force

Use this parameter to force the function to continue and perform any adjusting actions to successfully execute

Alias
Required False
Pipeline false
Default Value False
-InputObject

Allows piped input from Get-DbaDatabase

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

Set the delay in seconds to wait for the copy and/or restore jobs.
By default the delay is 5 seconds

Alias
Required False
Pipeline false
Default Value 5
-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