Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Backup frequency details from backup history Expand / Collapse
Author
Message
Posted Friday, March 4, 2011 8:28 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, September 19, 2014 12:12 AM
Points: 418, Visits: 582
Hi,
I have many backup frequency scheduled as Jobs or External CommVault in my server environment.
I just want to know if there is a way to identify the backup frequency if it's daily, weekly and monthly scheduled backup.
Backup may be either scheduled from Jobs or External CommVault.(So I cannot go with Jobs tables alone)
Query needs fetch details from backup History tables.

Any comments/suggestion is highly appriciated.

Thanks,
Bala
Post #1073368
Posted Sunday, March 6, 2011 10:17 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, August 18, 2014 3:04 AM
Points: 1,331, Visits: 15,269
Hopefully, this will help. It gets the information from msdb on job schedules. You will need to edit it to your purposes.


IF OBJECT_ID('tempdb..#xp_results') IS NOT NULL
BEGIN
DROP TABLE #xp_results
END

CREATE TABLE #xp_results (
job_id UNIQUEIDENTIFIER NOT NULL,
last_run_date INT NOT NULL,
last_run_time INT NOT NULL,
next_run_date INT NOT NULL,
next_run_time INT NOT NULL,
next_run_schedule_id INT NOT NULL,
requested_to_run INT NOT NULL,
request_source INT NOT NULL,
request_source_id sysname COLLATE database_default NULL,
running INT NOT NULL,
current_step INT NOT NULL,
current_retry_attempt INT NOT NULL,
job_state INT NOT NULL)

SELECT @is_sysadmin = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0)
SELECT @job_owner = SUSER_SNAME()


INSERT INTO #xp_results
EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner

SELECT '**************',' SQL AGENT JOB REFERENCES ','****************'

SELECT
j.job_id
, j.[name]
, j.date_modified
, j.version_number
, jss.subsystem
, jss.step_name
, CASE jss.on_success_action
WHEN 1 THEN 'Quit reporting success'
WHEN 2 THEN 'Quit reporting error'
WHEN 3 THEN 'Go to next step'
WHEN 4 THEN 'Go to step ' + convert(char(1), jss.on_success_step_id)
ELSE 'Unknown' END
, jss.database_name
, CASE j.enabled WHEN 1 THEN 'Yes' else 'No' END as Enabled
, CASE s.enabled WHEN 1 THEN 'Yes' else 'No' END as Scheduled
, CASE s.freq_type
WHEN 1 THEN 'Once'
WHEN 4 THEN 'Daily'
WHEN 8 THEN 'Weekly'
WHEN 16 THEN 'Monthly'
WHEN 32 THEN 'Monthly relative'
WHEN 64 THEN 'When SQL Server Agent starts'
WHEN 128 THEN 'Start whenever the CPU(s) become idle' END as Occurs
, CASE s.freq_type
WHEN 1 THEN 'O'
WHEN 4 THEN 'Every '
+ convert(varchar,s.freq_interval)
+ ' day(s)'
WHEN 8 THEN 'Every '
+ convert(varchar,s.freq_recurrence_factor)
+ ' weeks(s) on '
+ CASE WHEN s.freq_interval & 1 = 1 THEN + 'Sunday, ' END
+ CASE WHEN s.freq_interval & 1 = 1 THEN + 'Monday, ' END
+ CASE WHEN s.freq_interval & 1 = 1 THEN + 'Tuesday, ' END
+ CASE WHEN s.freq_interval & 1 = 1 THEN + 'Wednesday, ' END
+ CASE WHEN s.freq_interval & 1 = 1 THEN + 'Thursday, ' END
+ CASE WHEN s.freq_interval & 1 = 1 THEN + 'Friday, ' END
+ CASE WHEN s.freq_interval & 1 = 1 THEN + 'Saturday, ' END
--master.dbo.fn_freq_interval_desc(s.freq_interval)
WHEN 16 THEN 'Day ' + convert(varchar,s.freq_interval)
+ ' of every '
+ convert(varchar,s.freq_recurrence_factor)
+ ' month(s)'
WHEN 32 THEN 'The '
+ CASE s.freq_relative_interval
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 4 THEN 'Third'
WHEN 8 THEN 'Fourth'
WHEN 16 THEN 'Last' END
+ CASE s.freq_interval
WHEN 1 THEN ' Sunday'
WHEN 2 THEN ' Monday'
WHEN 3 THEN ' Tuesday'
WHEN 4 THEN ' Wednesday'
WHEN 5 THEN ' Thursday'
WHEN 6 THEN ' Friday'
WHEN 7 THEN ' Saturday'
WHEN 8 THEN ' Day'
WHEN 9 THEN ' Weekday'
WHEN 10 THEN ' Weekend Day' END
+ ' of every '
+ convert(varchar,s.freq_recurrence_factor)
+ ' month(s)' END AS Occurs_detail
, CASE s.freq_subday_type
WHEN 1 THEN 'Occurs once at '
--+ master.dbo.fn_Time2Str(s.active_start_time)
+ LEFT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2) + ':' + SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),3,2) + ':' + RIGHT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2)
WHEN 2 THEN 'Occurs every '
+ convert(varchar,s.freq_subday_interval)
+ ' Seconds(s) Starting at '
+ LEFT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2) + ':' + SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),3,2) + ':' + RIGHT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2)
+ ' ending at '
+ LEFT(RIGHT('000000' + CONVERT(VARCHAR,s.active_end_time),6),2) + ':' + SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR,s.active_end_time),6),3,2) + ':' + RIGHT(RIGHT('000000' + CONVERT(VARCHAR,s.active_end_time),6),2)
--+ master.dbo.fn_Time2Str(s.active_end_time)
WHEN 4 THEN 'Occurs every '
+ convert(varchar,s.freq_subday_interval)
+ ' Minute(s) Starting at '
+ LEFT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2) + ':' + SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),3,2) + ':' + RIGHT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2)
+ ' ending at '
+ LEFT(RIGHT('000000' + CONVERT(VARCHAR,s.active_end_time),6),2) + ':' + SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR,s.active_end_time),6),3,2) + ':' + RIGHT(RIGHT('000000' + CONVERT(VARCHAR,s.active_end_time),6),2)
WHEN 8 THEN 'Occurs every '
+ convert(varchar,s.freq_subday_interval)
+ ' Hour(s) Starting at '
+ LEFT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2) + ':' + SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),3,2) + ':' + RIGHT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2)
+ ' ending at '
+ LEFT(RIGHT('000000' + CONVERT(VARCHAR,s.active_end_time),6),2) + ':' + SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR,s.active_end_time),6),3,2) + ':' + RIGHT(RIGHT('000000' + CONVERT(VARCHAR,s.active_end_time),6),2)
END as Frequency
, CASE WHEN s.freq_type = 1 THEN 'On date: '
--+ master.dbo.fn_Date2Str(s.active_start_date)
+ RIGHT(LEFT(CONVERT(VARCHAR,s.active_start_date) + '00000000', 8),2) + '/' + SUBSTRING(LEFT(CONVERT(VARCHAR,s.active_start_date) + '00000000', 8),5,2) + '/' + LEFT(LEFT(CONVERT(VARCHAR,s.active_start_date) + '00000000', 8),4)
+ ' At time: '
+ LEFT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2) + ':' + SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),3,2) + ':' + RIGHT(RIGHT('000000' + CONVERT(VARCHAR,s.active_start_time),6),2)
WHEN s.freq_type < 64 THEN 'Start date: '
+ RIGHT(LEFT(CONVERT(VARCHAR,s.active_start_date) + '00000000', 8),2) + '/' + SUBSTRING(LEFT(CONVERT(VARCHAR,s.active_start_date) + '00000000', 8),5,2) + '/' + LEFT(LEFT(CONVERT(VARCHAR,s.active_start_date) + '00000000', 8),4)
+ ' end date: '
+ RIGHT(LEFT(CONVERT(VARCHAR,s.active_end_date) + '00000000', 8),2) + '/' + SUBSTRING(LEFT(CONVERT(VARCHAR,s.active_end_date) + '00000000', 8),5,2) + '/' + LEFT(LEFT(CONVERT(VARCHAR,s.active_end_date) + '00000000', 8),4) END as Duration
, RIGHT(LEFT(CONVERT(VARCHAR,xp.next_run_date) + '00000000', 8),2) + '/' + SUBSTRING(LEFT(CONVERT(VARCHAR,xp.next_run_date) + '00000000', 8),5,2) + '/' + LEFT(LEFT(CONVERT(VARCHAR,xp.next_run_date) + '00000000', 8),4) + ' '
+ LEFT(RIGHT('000000' + CONVERT(VARCHAR,xp.next_run_time),6),2) + ':' + SUBSTRING(RIGHT('000000' + CONVERT(VARCHAR,xp.next_run_time),6),3,2) + ':' + RIGHT(RIGHT('000000' + CONVERT(VARCHAR,xp.next_run_time),6),2) AS Next_Run_Date
--+ master.dbo.fn_Time2Str(xp.next_run_time) AS Next_Run_Date
FROM msdb.dbo.sysjobs j (NOLOCK)
LEFT OUTER JOIN msdb.dbo.sysjobschedules js (NOLOCK) ON j.job_id = js.job_id
LEFT OUTER JOIN msdb.dbo.sysjobsteps jss (NOLOCK) ON j.job_id = jss.job_id
LEFT OUTER JOIN msdb.dbo.sysschedules s (NOLOCK) ON js.schedule_id = s.schedule_id
LEFT OUTER JOIN msdb.dbo.syscategories c (NOLOCK) ON j.category_id = c.category_id
LEFT OUTER JOIN #xp_results xp (NOLOCK) ON j.job_id = xp.job_id
WHERE j.name like @like
OR j.[description] like @like
OR jss.database_name like @like
OR jss.step_name like @like
OR jss.command like @Like
ORDER BY j.name, jss.step_id

Post #1073864
Posted Sunday, March 6, 2011 10:20 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, August 18, 2014 3:04 AM
Points: 1,331, Visits: 15,269
Notice you mentioned alternative methods. Just searching my scripts now.
Post #1073866
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse