--RETURNS A RESULT SET CONTAINING STATUS AND OTHER INFORMATION FOR REGISTERED PRIMARY AND SECONDARY DATABASES ON A PRIMARY, SECONDARY, OR MONITOR SERVER. EXEC SP_HELP_LOG_SHIPPING_MONITOR --GET LOG SHIPPING SQL JOBS SELECT * FROM MSDB.DBO.SYSJOBS WHERE CATEGORY_ID = 6 --LOG SHIPPING: GET SQL JOB HISTORY: COPY JOB (INCLUDE YOUR JOBID) SELECT MSDB.DBO.AGENT_DATETIME(RUN_DATE, RUN_TIME) AS 'RUNDATETIME' ,* FROM MSDB.DBO.SYSJOBHISTORY WHERE JOB_ID = 'D74C0F28-8626-4FD2-AA8F-72D00DCF5FDD' --UNCOMMENT TO GET ONLY THE LAST RUN HISTORY AND MSDB.DBO.AGENT_DATETIME(RUN_DATE, RUN_TIME) = ( SELECT TOP 1 MSDB.DBO.AGENT_DATETIME(RUN_DATE, RUN_TIME) AS 'RUNDATETIME' FROM MSDB.DBO.SYSJOBHISTORY WHERE JOB_ID = 'D74C0F28-8626-4FD2-AA8F-72D00DCF5FDD' ORDER BY RUNDATETIME DESC ) ORDER BY RUNDATETIME DESC ,INSTANCE_ID DESC --EXEC MSDB.DBO.SP_HELP_JOBHISTORY @JOB_NAME = N'LS_COPY_XYZ' ; --GET LAST RUN HISTORY: RESTORE JOB (INCLUDE YOUR JOBID) SELECT MSDB.DBO.AGENT_DATETIME(RUN_DATE, RUN_TIME) AS 'RUNDATETIME' ,* FROM MSDB.DBO.SYSJOBHISTORY WHERE JOB_ID = 'E19D351F-22B8-4624-A8A2-102C094D5E84' --UNCOMMENT TO GET ONLY THE LAST RUN HISTORY AND MSDB.DBO.AGENT_DATETIME(RUN_DATE, RUN_TIME) = ( SELECT TOP 1 MSDB.DBO.AGENT_DATETIME(RUN_DATE, RUN_TIME) AS 'RUNDATETIME' FROM MSDB.DBO.SYSJOBHISTORY WHERE JOB_ID = 'E19D351F-22B8-4624-A8A2-102C094D5E84' ORDER BY RUNDATETIME DESC ) ORDER BY RUNDATETIME DESC ,INSTANCE_ID DESC --EXEC MSDB.DBO.SP_HELP_JOBHISTORY @JOB_NAME = N'LS_RESTORE_XYZ'; --STORES ALERT JOB ID SELECT * FROM MSDB.DBO.LOG_SHIPPING_MONITOR_ALERT --STORES ERROR DETAIL FOR LOG SHIPPING JOBS SELECT * FROM MSDB.DBO.LOG_SHIPPING_MONITOR_ERROR_DETAIL --STORES HISTORY DETAILS FOR LOG SHIPPING JOBS (AGENT SESSION DETAILS) SELECT * FROM MSDB.DBO.LOG_SHIPPING_MONITOR_HISTORY_DETAIL ORDER BY LOG_TIME DESC --STORES ONE MONITOR RECORD PER PRIMARY DATABASE IN EACH LOG SHIPPING CONFIGURATION SELECT * FROM MSDB.DBO.LOG_SHIPPING_MONITOR_PRIMARY --STORES ONE MONITOR RECORD PER SECONDARY DATABASE IN A LOG SHIPPING CONFIGURATION SELECT * FROM MSDB.DBO.LOG_SHIPPING_MONITOR_SECONDARY --STORES ONE RECORD FOR THE PRIMARY DATABASE IN A LOG SHIPPING CONFIGURATION SELECT * FROM MSDB.DBO.LOG_SHIPPING_PRIMARY_DATABASES; --STORES ONE RECORD PER SECONDARY DATABASE IN A LOG SHIPPING CONFIGURATION SELECT * FROM MSDB.DBO.LOG_SHIPPING_SECONDARY_DATABASES;
Labels
- Differences (38)
- MongoDB (13)
- MySQL (10)
- Oracle (6)
- ORACLE DBA (1)
- Performance Tuning (13)
- PTuning (3)
- Scenarios (4)
- Scripts (35)
- SQLDBA (99)
- SQLDeveloper (66)
- SSIS (5)
- SSRS (8)
- Troubleshooting (37)
Thursday, 20 July 2017
T-SQL scripts to monitor Logshipping in SQL Server
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment