Performance

New-sqmOlaSysDbBackupJob

Creates a single SQL Agent job that runs Ola Hallengren's DatabaseBackup procedure daily for the system databases (master, model, msdb), writing FULL backups to <BackupDirectory>\Sys-db.

Module: sqmSQLTool
Requires: dbatools
ShouldProcess: Yes
Output: PSCustomObject

Execution Flow

START dbatools available? throw error -BackupDirectory given? Yes Auto-detect via xp_instance_regread Load SqlVersionDetection.ps1 (jobs\) New-DbaAgentJob (OlaHH-SystemDatabases-FULL) Step: DatabaseBackup @Databases='SYSTEM_DATABASES', @Directory='...\Sys-db', @BackupType='FULL', @CleanupTime=48 sp_add_schedule + sp_attach_schedule (daily 21:15) Return PSCustomObject (OverallStatus=Success) DONE
Requires Ola Hallengren's DatabaseBackup stored procedure to already exist on the instance. The script loads version-detection logic from a hardcoded module path (jobs\SqlVersionDetection.ps1) to adjust the backup compression/verify options for the detected SQL Server version.

Parameters

ParameterTypeRequiredDescription
-SqlInstanceStringOptionalTarget SQL instance. Default: $env:COMPUTERNAME.
-SqlCredentialPSCredentialOptionalSQL authentication credential.
-BackupDirectoryStringOptionalBackup root path. Auto-detected from registry if omitted.
-JobNameStringOptionalDefault from config (OlaJobNameSysDbBackup) or OlaHH-SystemDatabases-FULL.
-JobCategoryStringOptionalDefault: Database Maintenance.
-ScheduleTimeStringOptionalDefault: 21:15.
-CleanupTimeIntOptionalHours to retain backup files. Default: 48.
-CompressStringOptionalY/N. Default: Y.
-VerifyStringOptionalY/N. Default: Y.
-CheckSumStringOptionalY/N. Default: Y.
-LogToTableStringOptionalY/N. Default: Y.
-OperatorNameStringOptionalSQL Agent operator for notifications.
-UpdateSwitchOptionalUpdates an existing job instead of failing.
-ContinueOnErrorSwitchOptionalContinues on a single-database backup error.
-EnableExceptionSwitchOptionalThrows terminating errors instead of returning an error status object.
-WhatIf / -ConfirmSwitchOptionalStandard ShouldProcess support.

Return Value

Returns a PSCustomObject with: SqlInstance, JobName, BackupDirectory, ScheduleTime, JobStatus, OverallStatus, Message.

Examples

Example 1 — Create with auto-detected backup path

New-sqmOlaSysDbBackupJob -SqlInstance "SQL01"

Example 2 — Explicit path and retention

New-sqmOlaSysDbBackupJob -SqlInstance "SQL01" -BackupDirectory "E:\Backup" -CleanupTime 72