Created
February 6, 2014 15:56
-
-
Save janikvonrotz/8846959 to your computer and use it in GitHub Desktop.
SQL Server: Schedule SQL Server Maintenance Solution Agent Jobs
#SQLServer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Cleanup | |
CommandLog cleanup one day per week | |
Job Name: CommandLog Cleanup | |
Execute on monday at 04:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'CommandLog Cleanup', @name=N'CommandLog Cleanup', | |
@enabled=1, | |
@freq_type=8, | |
@freq_interval=2, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=40000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
System databases | |
Full backup every day | |
Job Name: DatabaseBackup - SYSTEM_DATABASES - FULL | |
Execute at 23:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name = N'DatabaseBackup - SYSTEM_DATABASES - FULL', @name=N'DatabaseBackup - SYSTEM_DATABASES - FULL', | |
@enabled=1, | |
@freq_type=4, | |
@freq_interval=1, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140101, | |
@active_end_date=99991231, | |
@active_start_time=230000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
User databases | |
Differential backup all other days of the week | |
Job Name: DatabaseBackup - USER_DATABASES - DIFF | |
Execute on Monday to saturday at 21:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'DatabaseBackup - USER_DATABASES - DIFF', @name=N'DatabaseBackup - USER_DATABASES - DIFF', | |
@enabled=1, | |
@freq_type=8, | |
@freq_interval=126, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=210000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
User databases | |
Full backup one day per week | |
Job Name: DatabaseBackup - USER_DATABASES - FULL | |
Execute on sunday at 21:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'DatabaseBackup - USER_DATABASES - FULL', @name=N'DatabaseBackup - USER_DATABASES - FULL', | |
@enabled=1, | |
@freq_type=8, | |
@freq_interval=1, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=210000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
User databases | |
Transaction log backup every hour | |
Job Name: DatabaseBackup - USER_DATABASES - LOG | |
Execute at 06:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'DatabaseBackup - USER_DATABASES - LOG', @name=N'DatabaseBackup - USER_DATABASES - LOG', | |
@enabled=1, | |
@freq_type=4, | |
@freq_interval=1, | |
@freq_subday_type=8, | |
@freq_subday_interval=1, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=60000, | |
@active_end_time=55959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
System databases | |
Integrity check one day per week | |
Job Name: DatabaseIntegrityCheck - SYSTEM_DATABASES | |
Execute on sunday at 22:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'DatabaseIntegrityCheck - SYSTEM_DATABASES', @name=N'DatabaseIntegrityCheck - SYSTEM_DATABASES', | |
@enabled=1, | |
@freq_type=8, | |
@freq_interval=1, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=220000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
User databases | |
Integrity check one day per week | |
Job Name: DatabaseIntegrityCheck - USER_DATABASES | |
Execute on sunday at 20:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'DatabaseIntegrityCheck - USER_DATABASES', @name=N'DatabaseIntegrityCheck - USER_DATABASES', | |
@enabled=1, | |
@freq_type=8, | |
@freq_interval=1, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=200000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
User databases | |
Index maintenance one day per week | |
Job Name: IndexOptimize - USER_DATABASES | |
Execute on sunday at 19:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'IndexOptimize - USER_DATABASES', @name=N'IndexOptimize - USER_DATABASES', | |
@enabled=1, | |
@freq_type=8, | |
@freq_interval=1, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=190000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Cleanup | |
Output file cleanup one day per week | |
Job name: Output File Cleanup | |
Execute on monday at 04:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'Output File Cleanup', @name=N'Output File Cleanup', | |
@enabled=1, | |
@freq_type=8, | |
@freq_interval=2, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=40000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Cleanup | |
sp_delete_backuphistory one day per week | |
Job Name: sp_delete_backuphistory | |
Execute on monday at 04:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'sp_delete_backuphistory', @name=N'sp_delete_backuphistory', | |
@enabled=1, | |
@freq_type=8, | |
@freq_interval=2, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=40000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Cleanup | |
sp_purge_jobhistory one day per week | |
Job Name: sp_purge_jobhistory | |
Execute on monday at 04:00 | |
*/ | |
USE [msdb] | |
GO | |
DECLARE @schedule_id int | |
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'sp_purge_jobhistory', @name=N'sp_purge_jobhistory', | |
@enabled=1, | |
@freq_type=8, | |
@freq_interval=2, | |
@freq_subday_type=1, | |
@freq_subday_interval=0, | |
@freq_relative_interval=0, | |
@freq_recurrence_factor=1, | |
@active_start_date=20140207, | |
@active_end_date=99991231, | |
@active_start_time=40000, | |
@active_end_time=235959, @schedule_id = @schedule_id OUTPUT | |
select @schedule_id | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment