How to create SQL Maintanance Plan using “ola hallengren” solution.
To make SQL Maintenance Plan we will use solution provided on https://ola.hallengren.com/.
- Download following script https://ola.hallengren.com/scripts/MaintenanceSolution.sql
- Modify the following parts of the script
We will need to specify following part of script
USE [DBAdmin] -- Specify the database in which the objects will be created. We need to create this DB first using SQL Managment Studio
DECLARE @CreateJobs nvarchar(max) = 'Y' -- Specify whether jobs should be created.
DECLARE @BackupDirectory nvarchar(max) = N'B:\Backup' -- Specify the backup root directory. If no directory is specified, the default backup directory is used.
DECLARE @CleanupTime int = 1176 -- Time in hours, after which backup files are deleted. If no time is specified, then no backup files are deleted.
DECLARE @OutputFileDirectory nvarchar(max) = NULL -- Specify the output file directory. If no directory is specified, then the SQL Server error log directory is used.
DECLARE @LogToTable nvarchar(max) = 'Y' -- Log commands to a table.
- Open the SQL Managment Studio on the server or connect remotely , create new database "DBAdmin" and set Recovery model "Simple"
- Open the modified script MaintenanceSolution.sql and execute it , it should take a couple of seconds and you should get message that it was successfully done.
Note: Before executing the script I will go to check if there is an existing Maintenance Plan and we will disabled it by removing schedules.
- You will see new Jobs were created under SQL Server Agent > Jobs .
Left only to set Scheduling for all relevant jobs