Skip to content

Commit

Permalink
use current version
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasjordan committed Nov 14, 2024
1 parent 91a0250 commit 9c8e5a9
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bin/maintenancesolution/CommandExecute.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BEGIN
--// Source: https://ola.hallengren.com //--
--// License: https://ola.hallengren.com/license.html //--
--// GitHub: https://github.com/olahallengren/sql-server-maintenance-solution //--
--// Version: 2022-12-03 17:23:44 //--
--// Version: 2024-11-14 14:03:14 //--
----------------------------------------------------------------------------------------------------

SET NOCOUNT ON
Expand Down
72 changes: 62 additions & 10 deletions bin/maintenancesolution/DatabaseBackup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ALTER PROCEDURE [dbo].[DatabaseBackup]
@CleanupTime int = NULL,
@CleanupMode nvarchar(max) = 'AFTER_BACKUP',
@Compress nvarchar(max) = NULL,
@CompressionAlgorithm nvarchar(max) = NULL,
@CopyOnly nvarchar(max) = 'N',
@ChangeBackupType nvarchar(max) = 'N',
@BackupSoftware nvarchar(max) = NULL,
Expand Down Expand Up @@ -66,6 +67,7 @@ ALTER PROCEDURE [dbo].[DatabaseBackup]
@ObjectLevelRecoveryMap nvarchar(max) = 'N',
@ExcludeLogShippedFromLogBackup nvarchar(max) = 'Y',
@DirectoryCheck nvarchar(max) = 'Y',
@BackupOptions nvarchar(max) = NULL,
@StringDelimiter nvarchar(max) = ',',
@DatabaseOrder nvarchar(max) = NULL,
@DatabasesInParallel nvarchar(max) = 'N',
Expand All @@ -80,7 +82,7 @@ BEGIN
--// Source: https://ola.hallengren.com //--
--// License: https://ola.hallengren.com/license.html //--
--// GitHub: https://github.com/olahallengren/sql-server-maintenance-solution //--
--// Version: 2022-12-03 17:23:44 //--
--// Version: 2024-11-14 14:03:14 //--
----------------------------------------------------------------------------------------------------

SET NOCOUNT ON
Expand Down Expand Up @@ -279,6 +281,7 @@ BEGIN
SET @Parameters += ', @CleanupTime = ' + ISNULL(CAST(@CleanupTime AS nvarchar),'NULL')
SET @Parameters += ', @CleanupMode = ' + ISNULL('''' + REPLACE(@CleanupMode,'''','''''') + '''','NULL')
SET @Parameters += ', @Compress = ' + ISNULL('''' + REPLACE(@Compress,'''','''''') + '''','NULL')
SET @Parameters += ', @CompressionAlgorithm = ' + ISNULL('''' + REPLACE(@CompressionAlgorithm,'''','''''') + '''','NULL')
SET @Parameters += ', @CopyOnly = ' + ISNULL('''' + REPLACE(@CopyOnly,'''','''''') + '''','NULL')
SET @Parameters += ', @ChangeBackupType = ' + ISNULL('''' + REPLACE(@ChangeBackupType,'''','''''') + '''','NULL')
SET @Parameters += ', @BackupSoftware = ' + ISNULL('''' + REPLACE(@BackupSoftware,'''','''''') + '''','NULL')
Expand Down Expand Up @@ -550,7 +553,7 @@ BEGIN
GROUP BY tmpDatabases.DatabaseName) SelectedDatabases2
ON tmpDatabases.DatabaseName = SelectedDatabases2.DatabaseName

IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DatabaseName = ''))
IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DATALENGTH(DatabaseName) = 0))
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
SELECT 'The value for the parameter @Databases is not supported.', 16, 1
Expand Down Expand Up @@ -671,7 +674,7 @@ BEGIN
SELECT @ErrorMessage = @ErrorMessage + QUOTENAME(DatabaseName) + ', '
FROM @tmpDatabases
WHERE Selected = 1
AND DatabaseNameFS = ''
AND DATALENGTH(DatabaseNameFS) = 0
ORDER BY DatabaseName ASC
IF @@ROWCOUNT > 0
BEGIN
Expand All @@ -684,7 +687,7 @@ BEGIN
FROM @tmpDatabases
WHERE UPPER(DatabaseNameFS) IN(SELECT UPPER(DatabaseNameFS) FROM @tmpDatabases GROUP BY UPPER(DatabaseNameFS) HAVING COUNT(*) > 1)
AND UPPER(DatabaseNameFS) IN(SELECT UPPER(DatabaseNameFS) FROM @tmpDatabases WHERE Selected = 1)
AND DatabaseNameFS <> ''
AND DATALENGTH(DatabaseNameFS) > 0
ORDER BY DatabaseName ASC
OPTION (RECOMPILE)
IF @@ROWCOUNT > 0
Expand Down Expand Up @@ -961,7 +964,7 @@ BEGIN
--// Check URLs //--
----------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------
--// Get default compression algorithm //--
----------------------------------------------------------------------------------------------------

IF @CompressionAlgorithm IS NULL AND @BackupSoftware IS NULL AND @Version >= 16
BEGIN
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'
WHEN @BackupSoftware IS NULL AND EXISTS(SELECT * FROM sys.configurations WHERE name = 'backup compression algorithm' AND value_in_use = 2) THEN 'QAT_DEFLATE' END
END

----------------------------------------------------------------------------------------------------
--// Check input parameters //--
----------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1181,6 +1194,32 @@ BEGIN

----------------------------------------------------------------------------------------------------

IF @CompressionAlgorithm NOT IN ('MS_XPRESS','QAT_DEFLATE')
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
SELECT 'The value for the parameter @CompressionAlgorithm is not supported. The allowed values are MS_XPRESS and QAT_DEFLATE.', 16, 1
END

IF @CompressionAlgorithm IS NOT NULL AND NOT (@Version >= 16)
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
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
END

IF @CompressionAlgorithm = 'QAT_DEFLATE' AND NOT (SERVERPROPERTY('EngineEdition') IN(2, 3))
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
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
END

IF @CompressionAlgorithm IS NOT NULL AND @BackupSoftware IS NOT NULL
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
SELECT 'The value for the parameter @CompressionAlgorithm is not supported. Setting the compression algorithm is only supported with SQL Server native backup', 16, 4
END

----------------------------------------------------------------------------------------------------

IF @CopyOnly NOT IN ('Y','N') OR @CopyOnly IS NULL
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
Expand Down Expand Up @@ -1295,7 +1334,7 @@ BEGIN

----------------------------------------------------------------------------------------------------

IF @MaxTransferSize < 65536 OR @MaxTransferSize > 4194304
IF @MaxTransferSize < 65536 OR @MaxTransferSize > 20971520
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
SELECT 'The value for the parameter @MaxTransferSize is not supported.', 16, 1
Expand Down Expand Up @@ -1381,7 +1420,13 @@ BEGIN
SELECT 'The value for the parameter @NumberOfFiles is not supported.', 16, 9
END

----------------------------------------------------------------------------------------------------
IF @NumberOfFiles > 32 AND @URL LIKE 's3%' AND @MirrorURL LIKE 's3%'
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
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
END

----------------------------------------------------------------------------------------------------

IF @MinBackupSizeForMultipleFiles <= 0
BEGIN
Expand Down Expand Up @@ -1533,7 +1578,7 @@ BEGIN
SELECT 'The value for the parameter @Encrypt is not supported.', 16, 1
END

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

IF @URL IS NOT NULL AND @Credential IS NULL AND NOT EXISTS(SELECT * FROM sys.credentials WHERE UPPER(credential_identity) = 'SHARED ACCESS SIGNATURE')
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'))
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
SELECT 'The value for the parameter @Credential is not supported.', 16, 3
Expand Down Expand Up @@ -3532,6 +3577,11 @@ BEGIN
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
END

IF @Compress = 'Y' AND @CompressionAlgorithm IS NOT NULL
BEGIN
SET @CurrentCommand += ' (ALGORITHM = ' + @CompressionAlgorithm + ')'
END

IF @CurrentBackupType = 'DIFF' SET @CurrentCommand += ', DIFFERENTIAL'

IF EXISTS(SELECT * FROM @CurrentFiles WHERE Mirror = 1)
Expand All @@ -3547,6 +3597,7 @@ BEGIN
IF @BufferCount IS NOT NULL SET @CurrentCommand += ', BUFFERCOUNT = ' + CAST(@BufferCount AS nvarchar)
IF @CurrentMaxTransferSize IS NOT NULL SET @CurrentCommand += ', MAXTRANSFERSIZE = ' + CAST(@CurrentMaxTransferSize AS nvarchar)
IF @Description IS NOT NULL SET @CurrentCommand += ', DESCRIPTION = N''' + REPLACE(@Description,'''','''''') + ''''
IF @BackupOptions IS NOT NULL SET @CurrentCommand += ', BACKUP_OPTIONS = N''' + REPLACE(@BackupOptions,'''','''''') + ''''
IF @Encrypt = 'Y' SET @CurrentCommand += ', ENCRYPTION (ALGORITHM = ' + UPPER(@EncryptionAlgorithm) + ', '
IF @Encrypt = 'Y' AND @ServerCertificate IS NOT NULL SET @CurrentCommand += 'SERVER CERTIFICATE = ' + QUOTENAME(@ServerCertificate)
IF @Encrypt = 'Y' AND @ServerAsymmetricKey IS NOT NULL SET @CurrentCommand += 'SERVER ASYMMETRIC KEY = ' + QUOTENAME(@ServerAsymmetricKey)
Expand Down Expand Up @@ -3786,6 +3837,7 @@ BEGIN
SET @CurrentCommand += ' WITH '
IF @CheckSum = 'Y' SET @CurrentCommand += 'CHECKSUM'
IF @CheckSum = 'N' SET @CurrentCommand += 'NO_CHECKSUM'
IF @BackupOptions IS NOT NULL SET @CurrentCommand += ', RESTORE_OPTIONS = N''' + REPLACE(@BackupOptions,'''','''''') + ''''
IF @URL IS NOT NULL AND @Credential IS NOT NULL SET @CurrentCommand += ', CREDENTIAL = N''' + REPLACE(@Credential,'''','''''') + ''''
END

Expand Down
4 changes: 2 additions & 2 deletions bin/maintenancesolution/DatabaseIntegrityCheck.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BEGIN
--// Source: https://ola.hallengren.com //--
--// License: https://ola.hallengren.com/license.html //--
--// GitHub: https://github.com/olahallengren/sql-server-maintenance-solution //--
--// Version: 2022-12-03 17:23:44 //--
--// Version: 2024-11-14 14:03:14 //--
----------------------------------------------------------------------------------------------------

SET NOCOUNT ON
Expand Down Expand Up @@ -429,7 +429,7 @@ BEGIN
GROUP BY tmpDatabases.DatabaseName) SelectedDatabases2
ON tmpDatabases.DatabaseName = SelectedDatabases2.DatabaseName

IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DatabaseName = ''))
IF @Databases IS NOT NULL AND (NOT EXISTS(SELECT * FROM @SelectedDatabases) OR EXISTS(SELECT * FROM @SelectedDatabases WHERE DatabaseName IS NULL OR DATALENGTH(DatabaseName) = 0))
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
SELECT 'The value for the parameter @Databases is not supported.', 16, 1
Expand Down
4 changes: 2 additions & 2 deletions bin/maintenancesolution/IndexOptimize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BEGIN
--// Source: https://ola.hallengren.com //--
--// License: https://ola.hallengren.com/license.html //--
--// GitHub: https://github.com/olahallengren/sql-server-maintenance-solution //--
--// Version: 2022-12-03 17:23:44 //--
--// Version: 2024-11-14 14:03:14 //--
----------------------------------------------------------------------------------------------------

SET NOCOUNT ON
Expand Down Expand Up @@ -521,7 +521,7 @@ BEGIN
GROUP BY tmpDatabases.DatabaseName) SelectedDatabases2
ON tmpDatabases.DatabaseName = SelectedDatabases2.DatabaseName

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

0 comments on commit 9c8e5a9

Please sign in to comment.