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.
Brings log shipped secondary databases online for disaster recovery or planned migration scenarios
Recovers log shipped secondary databases from standby or restoring state to normal operational state. This function is essential for disaster recovery scenarios when you need to bring secondary databases online after a primary server failure, or for planned migrations where you want to switch roles between primary and secondary servers.
The recovery process handles the complete workflow automatically. First, it checks if the backup source directory is still accessible. If so, it ensures all available transaction log backups are copied by running the log shipping copy job. If the source directory is unreachable (common in disaster scenarios), it proceeds with available backups.
Next, it runs the log shipping restore job to apply any remaining transaction log backups that haven't been restored yet. Both the copy and restore jobs are monitored until completion, then disabled to prevent them from running again.
Finally, unless you specify -NoRecovery, the database is brought online by executing RESTORE DATABASE WITH RECOVERY. This makes the database fully accessible for reads and writes.
By default, all log shipped databases on the target instance are recovered. You can specify individual databases using the -Database parameter. The function requires that SQL Server Agent is running and will validate the service status before proceeding.
All operations are tracked through the msdb database log shipping tables to ensure consistency and proper sequencing of the recovery steps.
Invoke-DbaDbLogShipRecovery
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-Database] <String[]>]
[[-SqlCredential] <PSCredential>]
[-NoRecovery]
[-EnableException]
[-Force]
[[-InputObject] <Database[]>]
[[-Delay] <Int32>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Invoke-DbaDbLogShipRecovery -SqlInstance server1 -Force
Recovers all the databases on the instance that are enabled for log shipping
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
PS C:\> Invoke-DbaDbLogShipRecovery -SqlInstance server1 -database db_logship -Verbose
Recovers the database "db_logship" to a normal status
PS C:\> db1, db2, db3, db4 | Invoke-DbaDbLogShipRecovery -SqlInstance server1 -Verbose
Recovers the database db1, db2, db3, db4 to a normal status
PS C:\> Invoke-DbaDbLogShipRecovery -SqlInstance server1 -Force -WhatIf
Shows what would happen if the command were executed.
The target SQL Server instance or instances.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies the log-shipped secondary databases to recover. Accepts multiple database names and wildcards for pattern matching.
Use this when you need to recover specific databases instead of all log-shipped databases on the instance. Without specifying -Database, you must use -Force to recover all log-shipped databases.
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 |
Prevents the final RESTORE DATABASE WITH RECOVERY step that brings the database fully online. The database remains in restoring state after log shipping jobs complete.
Use this when you need to apply additional transaction logs manually or perform other operations before bringing the database online. By default, databases are fully recovered and made available for
read-write operations.
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 |
Bypasses the safety requirement to specify individual databases and processes all log-shipped databases on the instance. Also sets confirmation preference to none.
Use this in disaster recovery scenarios when you need to quickly recover all log-shipped databases without interactive prompts. Without -Force, you must explicitly specify database names using
-Database.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Accepts database objects from Get-DbaDatabase through the pipeline. This allows you to filter databases using Get-DbaDatabase and pipe them directly to the recovery function.
Particularly useful when you need to recover databases based on specific criteria like database state or properties rather than just database names.
Alias | |
Required | False |
Pipeline | true (ByValue) |
Default Value |
Sets the polling interval in seconds to check if the log shipping copy and restore jobs have completed. The function waits this long between status checks.
Use a shorter delay for faster recovery monitoring or a longer delay to reduce system load during job execution. Default is 5 seconds, which balances responsiveness with system performance.
Alias | |
Required | False |
Pipeline | false |
Default Value | 5 |
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 |