SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Backup frequency details from backup history


Backup frequency details from backup history

Author
Message
Bala'
Bala'
Mr or Mrs. 500
Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)

Group: General Forum Members
Points: 540 Visits: 620
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
MysteryJimbo
MysteryJimbo
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5215 Visits: 15346
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


MysteryJimbo
MysteryJimbo
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5215 Visits: 15346
Notice you mentioned alternative methods. Just searching my scripts now. :-D
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search