< Back

Invoke-DbaDbLogShipRecovery

Mon Jan 13, 2020 12:21 pm

NAME Invoke-DbaDbLogShipRecovery



SYNOPSIS

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





SYNTAX

Invoke-DbaDbLogShipRecovery [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

[[-Database] <System.String[]>] [[-SqlCredential] <Pscredential>] [-NoRecovery <Switch>] [-EnableException

<Switch>] [-Force <Switch>] [[-InputObject] <Microsoft.SqlServer.Management.Smo.Database[]>] [[-Delay] <Int>]

[<CommonParameters>]





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





PARAMETERS

-Database [<System.String[]>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Delay [<Int>]

Set the delay in seconds to wait for the copy and/or restore jobs.

By default the delay is 5 seconds



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Force [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InputObject [<Microsoft.SqlServer.Management.Smo.Database[]>]

Allows piped input from Get-DbaDatabase



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-NoRecovery [<Switch>]

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).



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: LogShipping

Author: Sander Stad (@sqlstad), sqlstad.nl



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Invoke-DbaDbLogShipRecovery -SqlInstance server1



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

-------------------------- EXAMPLE 2 --------------------------



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



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



Shows what would happen if the command were executed.



RELATED LINKS

https://dbatools.io/Invoke-DbaDbLogShipRecovery