Skip to content

Commit 8b922ad

Browse files
Include new version of SQL Server Maintenance Solution by Ola Hallengren (#9550)
1 parent 32a153e commit 8b922ad

File tree

5 files changed

+135
-31
lines changed

5 files changed

+135
-31
lines changed

bin/maintenancesolution/CommandExecute.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BEGIN
3636
--// Source: https://ola.hallengren.com //--
3737
--// License: https://ola.hallengren.com/license.html //--
3838
--// GitHub: https://github.com/olahallengren/sql-server-maintenance-solution //--
39-
--// Version: 2022-12-03 17:23:44 //--
39+
--// Version: 2024-11-14 14:03:14 //--
4040
----------------------------------------------------------------------------------------------------
4141

4242
SET NOCOUNT ON

bin/maintenancesolution/DatabaseBackup.sql

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ALTER PROCEDURE [dbo].[DatabaseBackup]
1616
@CleanupTime int = NULL,
1717
@CleanupMode nvarchar(max) = 'AFTER_BACKUP',
1818
@Compress nvarchar(max) = NULL,
19+
@CompressionAlgorithm nvarchar(max) = NULL,
1920
@CopyOnly nvarchar(max) = 'N',
2021
@ChangeBackupType nvarchar(max) = 'N',
2122
@BackupSoftware nvarchar(max) = NULL,
@@ -66,6 +67,7 @@ ALTER PROCEDURE [dbo].[DatabaseBackup]
6667
@ObjectLevelRecoveryMap nvarchar(max) = 'N',
6768
@ExcludeLogShippedFromLogBackup nvarchar(max) = 'Y',
6869
@DirectoryCheck nvarchar(max) = 'Y',
70+
@BackupOptions nvarchar(max) = NULL,
6971
@StringDelimiter nvarchar(max) = ',',
7072
@DatabaseOrder nvarchar(max) = NULL,
7173
@DatabasesInParallel nvarchar(max) = 'N',
@@ -80,7 +82,7 @@ BEGIN
8082
--// Source: https://ola.hallengren.com //--
8183
--// License: https://ola.hallengren.com/license.html //--
8284
--// GitHub: https://github.com/olahallengren/sql-server-maintenance-solution //--
83-
--// Version: 2022-12-03 17:23:44 //--
85+
--// Version: 2024-11-14 14:03:14 //--
8486
----------------------------------------------------------------------------------------------------
8587

8688
SET NOCOUNT ON
@@ -279,6 +281,7 @@ BEGIN
279281
SET @Parameters += ', @CleanupTime = ' + ISNULL(CAST(@CleanupTime AS nvarchar),'NULL')
280282
SET @Parameters += ', @CleanupMode = ' + ISNULL('''' + REPLACE(@CleanupMode,'''','''''') + '''','NULL')
281283
SET @Parameters += ', @Compress = ' + ISNULL('''' + REPLACE(@Compress,'''','''''') + '''','NULL')
284+
SET @Parameters += ', @CompressionAlgorithm = ' + ISNULL('''' + REPLACE(@CompressionAlgorithm,'''','''''') + '''','NULL')
282285
SET @Parameters += ', @CopyOnly = ' + ISNULL('''' + REPLACE(@CopyOnly,'''','''''') + '''','NULL')
283286
SET @Parameters += ', @ChangeBackupType = ' + ISNULL('''' + REPLACE(@ChangeBackupType,'''','''''') + '''','NULL')
284287
SET @Parameters += ', @BackupSoftware = ' + ISNULL('''' + REPLACE(@BackupSoftware,'''','''''') + '''','NULL')
@@ -550,7 +553,7 @@ BEGIN
550553
GROUP BY tmpDatabases.DatabaseName) SelectedDatabases2
551554
ON tmpDatabases.DatabaseName = SelectedDatabases2.DatabaseName
552555

553-
IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DatabaseName = ''))
556+
IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DATALENGTH(DatabaseName) = 0))
554557
BEGIN
555558
INSERT INTO @Errors ([Message], Severity, [State])
556559
SELECT 'The value for the parameter @Databases is not supported.', 16, 1
@@ -671,7 +674,7 @@ BEGIN
671674
SELECT @ErrorMessage = @ErrorMessage + QUOTENAME(DatabaseName) + ', '
672675
FROM @tmpDatabases
673676
WHERE Selected = 1
674-
AND DatabaseNameFS = ''
677+
AND DATALENGTH(DatabaseNameFS) = 0
675678
ORDER BY DatabaseName ASC
676679
IF @@ROWCOUNT > 0
677680
BEGIN
@@ -684,7 +687,7 @@ BEGIN
684687
FROM @tmpDatabases
685688
WHERE UPPER(DatabaseNameFS) IN(SELECT UPPER(DatabaseNameFS) FROM @tmpDatabases GROUP BY UPPER(DatabaseNameFS) HAVING COUNT(*) > 1)
686689
AND UPPER(DatabaseNameFS) IN(SELECT UPPER(DatabaseNameFS) FROM @tmpDatabases WHERE Selected = 1)
687-
AND DatabaseNameFS <> ''
690+
AND DATALENGTH(DatabaseNameFS) > 0
688691
ORDER BY DatabaseName ASC
689692
OPTION (RECOMPILE)
690693
IF @@ROWCOUNT > 0
@@ -961,7 +964,7 @@ BEGIN
961964
--// Check URLs //--
962965
----------------------------------------------------------------------------------------------------
963966

964-
IF EXISTS(SELECT * FROM @URLs WHERE Mirror = 0 AND DirectoryPath NOT LIKE 'https://%/%')
967+
IF EXISTS(SELECT * FROM @URLs WHERE Mirror = 0 AND NOT (DirectoryPath LIKE 'https://%/%' OR DirectoryPath LIKE 's3://%/%'))
965968
BEGIN
966969
INSERT INTO @Errors ([Message], Severity, [State])
967970
SELECT 'The value for the parameter @URL is not supported.', 16, 1
@@ -981,7 +984,7 @@ BEGIN
981984

982985
----------------------------------------------------------------------------------------------------
983986

984-
IF EXISTS(SELECT * FROM @URLs WHERE Mirror = 1 AND DirectoryPath NOT LIKE 'https://%/%')
987+
IF EXISTS(SELECT * FROM @URLs WHERE Mirror = 1 AND NOT (DirectoryPath LIKE 'https://%/%' OR DirectoryPath LIKE 's3://%/%'))
985988
BEGIN
986989
INSERT INTO @Errors ([Message], Severity, [State])
987990
SELECT 'The value for the parameter @MirrorURL is not supported.', 16, 1
@@ -1063,6 +1066,16 @@ BEGIN
10631066
WHEN @BackupSoftware IS NOT NULL AND @CompressionLevel = 0 THEN 'N' END
10641067
END
10651068

1069+
----------------------------------------------------------------------------------------------------
1070+
--// Get default compression algorithm //--
1071+
----------------------------------------------------------------------------------------------------
1072+
1073+
IF @CompressionAlgorithm IS NULL AND @BackupSoftware IS NULL AND @Version >= 16
1074+
BEGIN
1075+
SELECT @CompressionAlgorithm = CASE WHEN @BackupSoftware IS NULL AND EXISTS(SELECT * FROM sys.configurations WHERE name = 'backup compression algorithm' AND value_in_use = 1) THEN 'MS_XPRESS'
1076+
WHEN @BackupSoftware IS NULL AND EXISTS(SELECT * FROM sys.configurations WHERE name = 'backup compression algorithm' AND value_in_use = 2) THEN 'QAT_DEFLATE' END
1077+
END
1078+
10661079
----------------------------------------------------------------------------------------------------
10671080
--// Check input parameters //--
10681081
----------------------------------------------------------------------------------------------------
@@ -1181,6 +1194,32 @@ BEGIN
11811194

11821195
----------------------------------------------------------------------------------------------------
11831196

1197+
IF @CompressionAlgorithm NOT IN ('MS_XPRESS','QAT_DEFLATE')
1198+
BEGIN
1199+
INSERT INTO @Errors ([Message], Severity, [State])
1200+
SELECT 'The value for the parameter @CompressionAlgorithm is not supported. The allowed values are MS_XPRESS and QAT_DEFLATE.', 16, 1
1201+
END
1202+
1203+
IF @CompressionAlgorithm IS NOT NULL AND NOT (@Version >= 16)
1204+
BEGIN
1205+
INSERT INTO @Errors ([Message], Severity, [State])
1206+
SELECT 'The value for the parameter @CompressionAlgorithm is not supported. Specifying the compression algorithm is only supported in SQL Server 2022 and later.', 16, 2
1207+
END
1208+
1209+
IF @CompressionAlgorithm = 'QAT_DEFLATE' AND NOT (SERVERPROPERTY('EngineEdition') IN(2, 3))
1210+
BEGIN
1211+
INSERT INTO @Errors ([Message], Severity, [State])
1212+
SELECT 'The value for the parameter @CompressionAlgorithm is not supported. Setting the compression algorithm to QAT_DEFLATE is only supported in Standard and Enterprise Edition.', 16, 3
1213+
END
1214+
1215+
IF @CompressionAlgorithm IS NOT NULL AND @BackupSoftware IS NOT NULL
1216+
BEGIN
1217+
INSERT INTO @Errors ([Message], Severity, [State])
1218+
SELECT 'The value for the parameter @CompressionAlgorithm is not supported. Setting the compression algorithm is only supported with SQL Server native backup', 16, 4
1219+
END
1220+
1221+
----------------------------------------------------------------------------------------------------
1222+
11841223
IF @CopyOnly NOT IN ('Y','N') OR @CopyOnly IS NULL
11851224
BEGIN
11861225
INSERT INTO @Errors ([Message], Severity, [State])
@@ -1295,7 +1334,7 @@ BEGIN
12951334

12961335
----------------------------------------------------------------------------------------------------
12971336

1298-
IF @MaxTransferSize < 65536 OR @MaxTransferSize > 4194304
1337+
IF @MaxTransferSize < 65536 OR @MaxTransferSize > 20971520
12991338
BEGIN
13001339
INSERT INTO @Errors ([Message], Severity, [State])
13011340
SELECT 'The value for the parameter @MaxTransferSize is not supported.', 16, 1
@@ -1381,7 +1420,13 @@ BEGIN
13811420
SELECT 'The value for the parameter @NumberOfFiles is not supported.', 16, 9
13821421
END
13831422

1384-
----------------------------------------------------------------------------------------------------
1423+
IF @NumberOfFiles > 32 AND @URL LIKE 's3%' AND @MirrorURL LIKE 's3%'
1424+
BEGIN
1425+
INSERT INTO @Errors ([Message], Severity, [State])
1426+
SELECT 'The value for the parameter @NumberOfFiles is not supported. The maximum number of files when performing mirrored backups to S3 storage is 32.', 16, 10
1427+
END
1428+
1429+
----------------------------------------------------------------------------------------------------
13851430

13861431
IF @MinBackupSizeForMultipleFiles <= 0
13871432
BEGIN
@@ -1533,7 +1578,7 @@ BEGIN
15331578
SELECT 'The value for the parameter @Encrypt is not supported.', 16, 1
15341579
END
15351580

1536-
IF @Encrypt = 'Y' AND @BackupSoftware IS NULL AND NOT (@Version >= 12 AND (SERVERPROPERTY('EngineEdition') = 3) OR SERVERPROPERTY('EditionID') IN(-1534726760, 284895786))
1581+
IF @Encrypt = 'Y' AND @BackupSoftware IS NULL AND NOT (@Version >= 12 AND (SERVERPROPERTY('EngineEdition') IN(3, 8) OR SERVERPROPERTY('EditionID') IN(-1534726760, 284895786)))
15371582
BEGIN
15381583
INSERT INTO @Errors ([Message], Severity, [State])
15391584
SELECT 'The value for the parameter @Encrypt is not supported.', 16, 2
@@ -1738,7 +1783,7 @@ BEGIN
17381783
SELECT 'The value for the parameter @Credential is not supported.', 16, 2
17391784
END
17401785

1741-
IF @URL IS NOT NULL AND @Credential IS NULL AND NOT EXISTS(SELECT * FROM sys.credentials WHERE UPPER(credential_identity) = 'SHARED ACCESS SIGNATURE')
1786+
IF @URL IS NOT NULL AND @Credential IS NULL AND NOT EXISTS(SELECT * FROM sys.credentials WHERE UPPER(credential_identity) IN('SHARED ACCESS SIGNATURE','MANAGED IDENTITY','S3 ACCESS KEY'))
17421787
BEGIN
17431788
INSERT INTO @Errors ([Message], Severity, [State])
17441789
SELECT 'The value for the parameter @Credential is not supported.', 16, 3
@@ -3532,6 +3577,11 @@ BEGIN
35323577
SET @CurrentCommand += CASE WHEN @Compress = 'Y' AND (@CurrentIsEncrypted = 0 OR (@CurrentIsEncrypted = 1 AND ((@Version >= 13 AND @CurrentMaxTransferSize >= 65537) OR @Version >= 15.0404316 OR SERVERPROPERTY('EngineEdition') = 8))) THEN ', COMPRESSION' ELSE ', NO_COMPRESSION' END
35333578
END
35343579

3580+
IF @Compress = 'Y' AND @CompressionAlgorithm IS NOT NULL
3581+
BEGIN
3582+
SET @CurrentCommand += ' (ALGORITHM = ' + @CompressionAlgorithm + ')'
3583+
END
3584+
35353585
IF @CurrentBackupType = 'DIFF' SET @CurrentCommand += ', DIFFERENTIAL'
35363586

35373587
IF EXISTS(SELECT * FROM @CurrentFiles WHERE Mirror = 1)
@@ -3547,6 +3597,7 @@ BEGIN
35473597
IF @BufferCount IS NOT NULL SET @CurrentCommand += ', BUFFERCOUNT = ' + CAST(@BufferCount AS nvarchar)
35483598
IF @CurrentMaxTransferSize IS NOT NULL SET @CurrentCommand += ', MAXTRANSFERSIZE = ' + CAST(@CurrentMaxTransferSize AS nvarchar)
35493599
IF @Description IS NOT NULL SET @CurrentCommand += ', DESCRIPTION = N''' + REPLACE(@Description,'''','''''') + ''''
3600+
IF @BackupOptions IS NOT NULL SET @CurrentCommand += ', BACKUP_OPTIONS = N''' + REPLACE(@BackupOptions,'''','''''') + ''''
35503601
IF @Encrypt = 'Y' SET @CurrentCommand += ', ENCRYPTION (ALGORITHM = ' + UPPER(@EncryptionAlgorithm) + ', '
35513602
IF @Encrypt = 'Y' AND @ServerCertificate IS NOT NULL SET @CurrentCommand += 'SERVER CERTIFICATE = ' + QUOTENAME(@ServerCertificate)
35523603
IF @Encrypt = 'Y' AND @ServerAsymmetricKey IS NOT NULL SET @CurrentCommand += 'SERVER ASYMMETRIC KEY = ' + QUOTENAME(@ServerAsymmetricKey)
@@ -3786,6 +3837,7 @@ BEGIN
37863837
SET @CurrentCommand += ' WITH '
37873838
IF @CheckSum = 'Y' SET @CurrentCommand += 'CHECKSUM'
37883839
IF @CheckSum = 'N' SET @CurrentCommand += 'NO_CHECKSUM'
3840+
IF @BackupOptions IS NOT NULL SET @CurrentCommand += ', RESTORE_OPTIONS = N''' + REPLACE(@BackupOptions,'''','''''') + ''''
37893841
IF @URL IS NOT NULL AND @Credential IS NOT NULL SET @CurrentCommand += ', CREDENTIAL = N''' + REPLACE(@Credential,'''','''''') + ''''
37903842
END
37913843

bin/maintenancesolution/DatabaseIntegrityCheck.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ BEGIN
3939
--// Source: https://ola.hallengren.com //--
4040
--// License: https://ola.hallengren.com/license.html //--
4141
--// GitHub: https://github.com/olahallengren/sql-server-maintenance-solution //--
42-
--// Version: 2022-12-03 17:23:44 //--
42+
--// Version: 2024-11-14 14:03:14 //--
4343
----------------------------------------------------------------------------------------------------
4444

4545
SET NOCOUNT ON
@@ -429,7 +429,7 @@ BEGIN
429429
GROUP BY tmpDatabases.DatabaseName) SelectedDatabases2
430430
ON tmpDatabases.DatabaseName = SelectedDatabases2.DatabaseName
431431

432-
IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DatabaseName = ''))
432+
IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DATALENGTH(DatabaseName) = 0))
433433
BEGIN
434434
INSERT INTO @Errors ([Message], Severity, [State])
435435
SELECT 'The value for the parameter @Databases is not supported.', 16, 1

bin/maintenancesolution/IndexOptimize.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ BEGIN
5353
--// Source: https://ola.hallengren.com //--
5454
--// License: https://ola.hallengren.com/license.html //--
5555
--// GitHub: https://github.com/olahallengren/sql-server-maintenance-solution //--
56-
--// Version: 2022-12-03 17:23:44 //--
56+
--// Version: 2024-11-14 14:03:14 //--
5757
----------------------------------------------------------------------------------------------------
5858

5959
SET NOCOUNT ON
@@ -521,7 +521,7 @@ BEGIN
521521
GROUP BY tmpDatabases.DatabaseName) SelectedDatabases2
522522
ON tmpDatabases.DatabaseName = SelectedDatabases2.DatabaseName
523523

524-
IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DatabaseName = ''))
524+
IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DATALENGTH(DatabaseName) = 0))
525525
BEGIN
526526
INSERT INTO @Errors ([Message], Severity, [State])
527527
SELECT 'The value for the parameter @Databases is not supported.', 16, 1

0 commit comments

Comments
 (0)