I want get html report from log shipping

  • I want to get HTML report from log shipping, here is my script... please modify it 

    ##setup data source
    $dataSource1 = "MANU\PRACTICE"      ##SQL instance name
    $database1 = "MASTER"          ##Database name
    $dataSource2 = "MANU"      ##SQL instance name
    $database2 = "MASTER"          ##Database name
    $sqlCommand = "exec sp_help_log_shipping_monitor"     ##The T-SQL command to execute
    $TableHeader = "Log_shipping_status"      ##The title of the HTML page
    $Todaydate = (Get-date).toString("yyyyMMddhhmmss")
    $FileDir="D:\logshipping\"  #Directory where you need to save Reports
    $OutputFile = $FileDir+$Todaydate+"-LogshippingReport.html"     ##The file location
    ##set HTML formatting
    $Header = @"
    <style>
    TABLE {border-width: 1px;border-style: solid;border-color:  black;border-collapse: collapse;}
    TR:Nth-Child(Even) {Background-Color: #dddddd;}
    TH {border-width: 1px;padding: 3px;border-style: solid;border-color:  black;background-color: #6495ED;}
    TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
    </style>
    <title>
    Log_shipping_status
    </title>
    "@
    $body = @"
    "@
    $pre="<h1>Log_shipping_status</h1>"
    ##Create a string variable with all our connection details
    $connectionDetails = "Provider=sqloledb; " +
        "Data Source=$dataSource; " +
        "Initial Catalog=$database; " +
        "Integrated Security=SSPI;"

    ##Connect to the data source using the connection details and T-SQL command we provided above, and open the connection
    $connection = New-Object System.Data.OleDb.OleDbConnection $connectionDetails
    $command = New-Object System.Data.OleDb.OleDbCommand $sqlCommand,$connection
    $connection.Open()

    ##Get the results of our command into a DataSet object, and close the connection
    $dataAdapter = New-Object System.Data.OleDb.OleDbDataAdapter $command
    $dataSet = New-Object System.Data.DataSet
    $dataAdapter.Fill($dataSet)
    $connection.Close()

    ##Return all of the rows and pipe it into the ConvertTo-HTML cmdlet, and then pipe that into our output file
    $dataSet.Tables | Select-Object -Expand Rows |
    ConvertTo-HTML -Property server, database_name,last_backup_file, last_copied_file, last_restored_file -head $Header -body $body -PreContent $pre|
    Out-File $OutputFile


  • This is my output, Please help me. I want  to get copy and restore also

  • What doesn't work?

  • You suppose to execute this script in the destination server to get the data for those columns.

    Alex S
  • What scripting language is this?
    Why don't you create a SQL Server Agent job and have it email you in html format directly?

  • RandomStream - Thursday, January 4, 2018 4:50 PM

    What scripting language is this?
    Why don't you create a SQL Server Agent job and have it email you in html format directly?

    Looks like PowerShell.
    However, I may be wrong.

  • Lynn Pettis - Thursday, January 4, 2018 5:47 PM

    RandomStream - Thursday, January 4, 2018 4:50 PM

    What scripting language is this?
    Why don't you create a SQL Server Agent job and have it email you in html format directly?

    Looks like PowerShell.
    However, I may be wrong.

    Mastering it already...yes it's Powershell. Sir  🙂

    Sue

  • manu.manohar033 - Thursday, December 21, 2017 8:29 AM

    I want to get HTML report from log shipping, here is my script... please modify it 

    ##setup data source
    $dataSource1 = "MANU\PRACTICE"      ##SQL instance name
    $database1 = "MASTER"          ##Database name
    $dataSource2 = "MANU"      ##SQL instance name
    $database2 = "MASTER"          ##Database name
    $sqlCommand = "exec sp_help_log_shipping_monitor"     ##The T-SQL command to execute
    $TableHeader = "Log_shipping_status"      ##The title of the HTML page
    $Todaydate = (Get-date).toString("yyyyMMddhhmmss")
    $FileDir="D:\logshipping\"  #Directory where you need to save Reports
    $OutputFile = $FileDir+$Todaydate+"-LogshippingReport.html"     ##The file location
    ##set HTML formatting
    $Header = @"
    <style>
    TABLE {border-width: 1px;border-style: solid;border-color:  black;border-collapse: collapse;}
    TR:Nth-Child(Even) {Background-Color: #dddddd;}
    TH {border-width: 1px;padding: 3px;border-style: solid;border-color:  black;background-color: #6495ED;}
    TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
    </style>
    <title>
    Log_shipping_status
    </title>
    "@
    $body = @"
    "@
    $pre="<h1>Log_shipping_status</h1>"
    ##Create a string variable with all our connection details
    $connectionDetails = "Provider=sqloledb; " +
        "Data Source=$dataSource; " +
        "Initial Catalog=$database; " +
        "Integrated Security=SSPI;"

    ##Connect to the data source using the connection details and T-SQL command we provided above, and open the connection
    $connection = New-Object System.Data.OleDb.OleDbConnection $connectionDetails
    $command = New-Object System.Data.OleDb.OleDbCommand $sqlCommand,$connection
    $connection.Open()

    ##Get the results of our command into a DataSet object, and close the connection
    $dataAdapter = New-Object System.Data.OleDb.OleDbDataAdapter $command
    $dataSet = New-Object System.Data.DataSet
    $dataAdapter.Fill($dataSet)
    $connection.Close()

    ##Return all of the rows and pipe it into the ConvertTo-HTML cmdlet, and then pipe that into our output file
    $dataSet.Tables | Select-Object -Expand Rows |
    ConvertTo-HTML -Property server, database_name,last_backup_file, last_copied_file, last_restored_file -head $Header -body $body -PreContent $pre|
    Out-File $OutputFile

    The script itself runs fine - just ran it.
    The issue looks like something with log shipping itself.  Manually execute sp_help_log_shipping_monitor in the master database on the primary - if there are no rows for the copy or the restore then it's that process itself.
    Check the LS_copy job and the LS_restore job on the secondary and make sure SQL Server Agent is running on the secondary.

    Sue

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply