< Back

Install-DbaMaintenanceSolution

Mon Jan 13, 2020 12:06 pm

NAME Install-DbaMaintenanceSolution



SYNOPSIS

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





SYNTAX

Install-DbaMaintenanceSolution [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>

[[-SqlCredential] <Pscredential>] [[-Database] <System.Object>] [[-BackupLocation] <String>] [[-CleanupTime]

<Int>] [[-OutputFileDirectory] <String>] [-ReplaceExisting <Switch>] [-LogToTable <Switch>] [[-Solution] <String>]

[-InstallJobs <Switch>] [[-LocalFile] <String>] [-Force <Switch>] [-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

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

Hallengren





PARAMETERS

-BackupLocation [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-CleanupTime [<Int>]

Time in hours, after which backup files are deleted.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Database [<System.Object>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Force [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InstallJobs [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-LocalFile [<String>]

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-se ... e-solution



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-LogToTable [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-OutputFileDirectory [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ReplaceExisting [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Solution [<String>]

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

IntegrityCheck and IndexOptimize.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: Community, OlaHallengren

Author: Viorel Ciucu, cviorel.com



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



https://ola.hallengren.com



-------------------------- 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'



RELATED LINKS

http://dbatools.io/Install-DbaMaintenanceSolution