You can validate the status of log-shipping to a secondary server if you suspect it has been broken. Below is the script, which uses the SQLPS module:
1 |
Invoke-Sqlcmd -ServerInstance MySqlServer {SELECT secondary_database, last_restored_date FROM msdb.dbo.log_shipping_secondary_databases} |
If you are ambitious, you can add a function to your profile such as the one below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<# .SYNOPSIS Displays a list of secondary, log-shipped databases and last_restored_date on the SQL Server provided. .DESCRIPTION Displays a list of secondary, log-shipped databases and last_restored_date on the SQL Server provided. .EXAMPLE PS C:\> Check-LogShipping MySqlServer .PARAMETER SQLServerName Specifies the SQL Server instance name. .OUTPUTS string .NOTES Additional information about the function. #> function Check-LogShipping { [CmdletBinding(DefaultParameterSetName = 'SqlServerInstance')] [OutputType([string], ParameterSetName = 'SqlServerInstance')] [OutputType([string])] param ([Parameter(Mandatory = $true)][string]$SqlServerInstance) switch ($PsCmdlet.ParameterSetName) { 'SqlServerInstance' { # Main block of code` If ($SqlServerInstance:paramMissing) { throw "USAGE: Check-LogShipping -SqlServerInstance <server name>" } #$local:paramMissing try { Invoke-Sqlcmd -ServerInstance $SqlServerInstance { SELECT secondary_database, last_restored_date FROM msdb.dbo.log_shipping_secondary_databases } | Format-Table -AutoSize } catch { Out-Host $_.Exception.Message } break } } } |
Views – 3902