dbatools is a free PowerShell module with over 300 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Invoke-DbaLogShippingRecovery

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.

Screenshots

dbatools-Invoke-DbaLogShippingRecovery

Examples

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

Invoke-DbaLogShippingRecovery -SqlServer ‘server1’

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

Invoke-DbaLogShippingRecovery -SqlServer ‘server1’ -SqlCredential $cred -Verbose

Recovers the database “db_logship” to a normal status.

Invoke-DbaLogShippingRecovery -SqlServer ‘server1’ -database ‘db_logship’ -Verbose

Recovers the databases db1, db2, db3, db4 to a normal status.

db1, db2, db3, db4 | Invoke-DbaLogShippingRecovery -SqlServer ‘server1’ -Verbose

Author

This command was created by Sander Stad. You can find Sander on Twitter and his blog.

Get-Help

From PowerShell, execute Get-Help Invoke-DbaLogShippingRecovery -Detailed for more information on this function.

Source Code

Want to see the source code? View Invoke-DbaLogShippingRecovery.ps1 on GitHub
 

Related commands