Many of DBAs already started using the Ola hallengren’s maintenance plan script. It is a free script replacing traditional GUI maintenance plan. It is very good script for all type and variety of database, application and size.
He is a Microsoft award winner for hismaintenance plan script.Here is the steps, how to use effectively for many servers. You can use a CMS if you registered it or one be one.
Job and SP creationhttps://ola.hallengren.com/downloads.html ― You can download all in one-shot or needed one.
Create a dedicated DB called DBA_DB or by default it uses master DB and run the downloaded script USE [master] ― Specify the database in which the objects will be created.There are lots of parameters in each job. Please open the website and read it. I have included the important parameters.
Parameters Ex: Skip database “USER_DATABASES, -Db1″mostly I used.
Value Description SYSTEM_DATABASES All system databases (master, msdb, and model) USER_DATABASES All user databases ALL_DATABASES All databases AVAILABILITY_GROUP_DATABASES All databases in availability groups USER_DATABASES, -AVAILABILITY_GROUP_DATABASES All user databases that are not in availability groups Db1 The database Db1 Db1, Db2 The databases Db1 and Db2 USER_DATABASES, -Db1 All user databases, except Db1 %Db% All databases that have “Db” in the name %Db%, -Db1 All databases that have “Db” in the name, except Db1 ALL_DATABASES, -%Db% All databases that do not have “Db” in the nameChanges needed In the script:
Change the use master to DBA_DB ,If we do not have DBA_DB, create one Or you can go with master. Change the backup location “@BackupDirectory ” in the SET parameter, per organization location (You can take a look of the backup history system table for the location)The Ola script take a root directory from location “@BackupDirectory ” and create a sub directory per DBs
Ex: Root: C:\backup
Per DB: full backup : C:\backup\DB_name\full\ & Diff backup : C:\backup\DB_name\diff\ & Log backup : C:\backup\DB_name\log\
Run the script. It will create a four SP, one table in the DBA_DB and it will create 11 jobs in the agent, two will be removed by customized script “[sp_delete_backuphistory] & [sp_purge_jobhistory]”, I need this for history use. Update retention by day or hours on the stepsNote: Change the Verify = ‘N’ for VLDB larger databases.
Example: sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR))-d DBA_DB -Q “EXECUTE [dbo].[DatabaseBackup] @Databases = ‘USER_DATABASES’, @Directory = N’\WIN-PC\DB_Backups ‘, @BackupType = ‘LOG’, @Verify = ‘N’ , @CleanupTime = 192, @CheckSum = ‘Y’, @ChangeBackupType=’Y’ , @LogToTable = ‘Y'” bThis is an important step. The job by default will create with retention NULL, we need to open each step and need to pass the retention days or hours as below.
Use the notepad and replace each step of the jobs Make sure you have changed the backup location in the notepad.
First use CTRL+H and replace the backup location with right path Ex: \WIN-PC\DB_Backups
Open each job and replace the following commands: It is easy.
Previously he used CMD mode of scripts.
==========================================
-- Job: Command Log Cleanup DELETE FROM [dbo].[CommandLog] WHERE StartTime < DATEADD(dd,-130,GETDATE()) -- Job: DatabaseBackup - SYSTEM_DATABASES - FULL EXECUTE [dbo].[DatabaseBackup] @Databases = 'SYSTEM_DATABASES', @Directory = '\\WIN-PC\DB_Backups', @BackupType = 'FULL', @Verify = 'Y', @CleanupTime = 192, @CheckSum = 'Y', @LogToTable = 'Y' -- Job: DatabaseBackup - USER_DATABASES - DIFF EXECUTE [dbo].[DatabaseBackup] @Databases = 'USER_DATABASES', @Directory = '\\WIN-PC\DB_Backups', @BackupType = 'DIFF', @Verify = 'Y', @CleanupTime = 192, @CheckSum = 'Y', @ChangeBackupType='Y', @LogToTable = 'Y' -- Job: DatabaseBackup - USER_DATABASES - FULL EXECUTE [dbo].[DatabaseBackup] @Databases = 'USER_DATABASES', @Directory = '\\WIN-PC\DB_Backups', @BackupType = 'FULL', @Verify = 'N', @CleanupTime = 336, @CheckSum = 'Y', @ChangeBackupType='Y', @LogToTable = 'Y' -- Job: DatabaseBackup - USER_DATABASES - LOG EXECUTE [dbo].[DatabaseBackup] @Databases = 'USER_DATABASES', @Directory = '\\WIN-PC\DB_Backups', @BackupType = 'LOG', @Verify = 'Y', @CleanupTime = 192, @CheckSum = 'Y', @ChangeBackupType='Y', @LogToTable = 'Y' -- Job: DatabaseIntegrityCheck - SYSTEM_DATABASES No changes -- Job: DatabaseIntegrityCheck - USER_DATABASES No changes -- Job: IndexOptimize - USER_DATABASES EXECUTE [dbo].[IndexOptimize] @Databases = 'USER_DATABASES', @UpdateStatistics = 'ALL',@OnlyModifiedStatistics = 'Y',@PartitionLevel = 'Y',@LogToTable = 'Y' -- Job: Output File Cleanup No changes==========================================
Calculation to Days: 336/24 = 14 Days. The retention can be changed.
Job Name Default Value We need to change Example Command Log Cleanup 30 Days 130 Days (dd,-130,GETDATE()) DatabaseBackup SYSTEM_DATABASES FULL NULL 120 Hours @CleanupTime =120 DatabaseBackup USER_DATABASES DIFF NULL 192 Hours @CleanupTime =192 DatabaseBackup USER_DATABASES FULL NULL 336 Hours @CleanupTime =336 DatabaseBackup USER_DATABASES LOG NULL 192 Hours @CleanupTime =192 DatabaseIntegrityCheck SYSTEM_DATABASES N/A N/A N/A DatabaseIntegrityCheck USER_DATABASES N/A N/A N/A IndexOptimize USER_DATABASES N/A N/A N/A Output File Cleanup 30 Days No Changes N/A Create and Update job schedule:This master script by default will not create a schedule.
I have customized script for that, which will create a following DBA standard schedule. The schedule can be changed for larger databases and more than one instance running on the server.
Run this attached script.