commands

^

Install-DbaMaintenanceSolution

Author Viorel Ciucu, cviorel.com
Availability Windows, Linux, macOS

 

Synopsis

Download and Install SQL Server Maintenance Solution created by Ola Hallengren (https://ola.hallengren.com)

Description

This script will download and install the latest version of SQL Server Maintenance Solution created by Ola Hallengren

Syntax

Install-DbaMaintenanceSolution
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object>]
    [[-BackupLocation] <String>]
    [[-CleanupTime] <Int32>]
    [[-OutputFileDirectory] <String>]
    [-ReplaceExisting]
    [-LogToTable]
    [[-Solution] <String[]>]
    [-InstallJobs]
    [[-LocalFile] <String>]
    [-Force]
    [-InstallParallel]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -CleanupTime 72

Installs Ola Hallengren's Solution objects on RES14224 in the DBA database.
Backups will default to the default Backup Directory.
If the Maintenance Solution already exists, the script will be halted.

Example: 2
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -BackupLocation "Z:\SQLBackup" -CleanupTime 72

This will create the Ola Hallengren's Solution objects. Existing objects are not affected in any way.

Example: 3
PS C:\> $params = @{
>> SqlInstance = 'MyServer'
>> Database = 'maintenance'
>> ReplaceExisting = $true
>> InstallJobs = $true
>> LogToTable = $true
>> BackupLocation = 'C:\Data\Backup'
>> CleanupTime = 65
>> Verbose = $true
>> }
>> Install-DbaMaintenanceSolution @params

Installs Maintenance Solution to myserver in database. Adds Agent Jobs, and if any currently exist, they'll be replaced.

Example: 4
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -BackupLocation "Z:\SQLBackup" -CleanupTime 72 -ReplaceExisting

This will drop and then recreate the Ola Hallengren's Solution objects
The cleanup script will drop and recreate:

  • TABLE [dbo].[CommandLog]
  • STORED PROCEDURE [dbo].[CommandExecute]
  • STORED PROCEDURE [dbo].[DatabaseBackup]
  • STORED PROCEDURE [dbo].[DatabaseIntegrityCheck]
  • STORED PROCEDURE [dbo].[IndexOptimize]
    The following SQL Agent jobs will be deleted:
  • 'Output File Cleanup'
  • 'IndexOptimize - USER_DATABASES'
  • 'sp_delete_backuphistory'
  • 'DatabaseBackup - USER_DATABASES - LOG'
  • 'DatabaseBackup - SYSTEM_DATABASES - FULL'
  • 'DatabaseBackup - USER_DATABASES - FULL'
  • 'sp_purge_jobhistory'
  • 'DatabaseIntegrityCheck - SYSTEM_DATABASES'
  • 'CommandLog Cleanup'
  • 'DatabaseIntegrityCheck - USER_DATABASES'
  • 'DatabaseBackup - USER_DATABASES - DIFF'
Example: 5
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -InstallParallel

This will create the Queue and QueueDatabase tables for uses when manually changing jobs to use the @DatabasesInParallel = 'Y' flag

Required Parameters

-SqlInstance

The target SQL Server instance onto which the Maintenance Solution will be installed.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential). Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported. For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-Database

The database where Ola Hallengren's solution will be installed. Defaults to master.

Alias
Required False
Pipeline false
Default Value master
-BackupLocation

Location of the backup root directory. If this is not supplied, the default backup directory will be used.

Alias
Required False
Pipeline false
Default Value
-CleanupTime

Time in hours, after which backup files are deleted.

Alias
Required False
Pipeline false
Default Value 0
-OutputFileDirectory

Specify the output file directory where the Maintenance Solution will write to.

Alias
Required False
Pipeline false
Default Value
-ReplaceExisting

If this switch is enabled, objects already present in the target database will be dropped and recreated.

Alias
Required False
Pipeline false
Default Value False
-LogToTable

If this switch is enabled, the Maintenance Solution will be configured to log commands to a table.

Alias
Required False
Pipeline false
Default Value False
-Solution

Specifies which portion of the Maintenance solution to install. Valid values are All (full solution), Backup, IntegrityCheck and IndexOptimize.

Alias
Required False
Pipeline false
Default Value All
Accepted Values All,Backup,IntegrityCheck,IndexOptimize
-InstallJobs

If this switch is enabled, the corresponding SQL Agent Jobs will be created.

Alias
Required False
Pipeline false
Default Value False
-LocalFile

Specifies the path to a local file to install Ola's solution from. This should be the zip file as distributed by the maintainers. If this parameter is not specified, the latest version will be downloaded and installed from https://github.com/olahallengren/sql-server-maintenance-solution

Alias
Required False
Pipeline false
Default Value
-Force

If this switch is enabled, the Ola's solution will be downloaded from the internet even if previously cached.

Alias
Required False
Pipeline false
Default Value False
-InstallParallel

If this switch is enabled, the Queue and QueueDatabase tables are created, for use when @DatabasesInParallel = 'Y' are set in the jobs.

Alias
Required False
Pipeline false
Default Value False
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.

Alias cf
Required False
Pipeline false
Default Value

 

Want to see the source code for this command? Check out Install-DbaMaintenanceSolution on GitHub.
Want to see the Bill Of Health for this command? Check out Install-DbaMaintenanceSolution.