@@ -110,6 +110,10 @@ SELECT @crlf = NCHAR(13) + NCHAR(10),
110110 @StartTime = DATEADD (hh, @HoursBack, GETDATE ()),
111111 @MoreInfoHeader = ' <?ClickToSeeDetails -- ' + @crlf, @MoreInfoFooter = @crlf + ' -- ?>' ;
112112
113+ SET @ProductVersion = CAST (SERVERPROPERTY (' ProductVersion' ) AS NVARCHAR (128 ));
114+ SELECT @ProductVersionMajor = SUBSTRING (@ProductVersion, 1 , CHARINDEX (' .' , @ProductVersion) + 1 ),
115+ @ProductVersionMinor = PARSENAME (CONVERT (VARCHAR (32 ), @ProductVersion), 2 );
116+
113117CREATE TABLE #Backups
114118(
115119 id INT IDENTITY (1 , 1 ),
@@ -989,6 +993,11 @@ RAISERROR('Rules analysis starting', 0, 1) WITH NOWAIT;
989993
990994 /* Checking for encrypted backups and the last backup of the encryption key.*/
991995
996+ /* 2014 ONLY*/
997+
998+ IF @ProductVersionMajor >= 12
999+ BEGIN
1000+
9921001 SET @StringToExecute = N ' SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;' + @crlf;
9931002
9941003 SET @StringToExecute + = N' SELECT
@@ -1012,6 +1021,8 @@ RAISERROR('Rules analysis starting', 0, 1) WITH NOWAIT;
10121021 INSERT #Warnings ( CheckId, Priority, DatabaseName, Finding, Warning )
10131022 EXEC sys .sp_executesql @StringToExecute;
10141023
1024+ END
1025+
10151026 /* Looking for backups that have BULK LOGGED data in them -- this can screw up point in time LOG recovery.*/
10161027
10171028 SET @StringToExecute = N ' SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;' + @crlf;
@@ -1233,6 +1244,36 @@ END
12331244
12341245 EXEC sp_executesql @InnerStringToExecute
12351246
1247+ /* We need to add the encryptor column if it doesn't exist, in case someone wants to push data from a 2014 instance to a 2012 repo.*/
1248+
1249+
1250+ SET @StringToExecute = N ' SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;' + @crlf;
1251+
1252+ SET @StringToExecute + = '
1253+
1254+ IF NOT EXISTS (
1255+ SELECT 1
1256+ FROM ' + QUOTENAME (@WriteBackupsToDatabaseName) + N' .sys.column AS c
1257+ WHERE OBJECT_NAME(c.object_id) = ?
1258+ AND c.name = ?
1259+ )
1260+
1261+ BEGIN
1262+
1263+ ALTER TABLE ' + QUOTENAME (@WriteBackupsToDatabaseName) + N' .[dbo].[backupset] ADD [encryptor_type] NVARCHAR(32)
1264+
1265+ END
1266+ '
1267+
1268+ SET @InnerStringToExecute = N ' EXEC( '' ' + @StringToExecute + ' '' , '' backupset'' , '' encryptor_type'' ) AT ' + QUOTENAME (@WriteBackupsToListenerName) + N ' ;'
1269+
1270+ IF @Debug = 1
1271+ PRINT @InnerStringToExecute;
1272+
1273+ EXEC sp_executesql @InnerStringToExecute
1274+
1275+
1276+
12361277 RAISERROR (' We'' ll even make the indexes!' , 0 , 1 ) WITH NOWAIT
12371278
12381279 /* Checking for and creating the PK/CX*/
@@ -1438,11 +1479,18 @@ END
14381479 '
14391480 SET @StringToExecute + = N' (database_name, database_guid, backup_set_uuid, type, backup_size, backup_start_date, backup_finish_date, media_set_id,
14401481 compressed_backup_size, recovery_model, server_name, machine_name, first_lsn, last_lsn, user_name, compatibility_level,
1441- is_password_protected, is_snapshot, is_readonly, is_single_user, has_backup_checksums, is_damaged, encryptor_type, has_bulk_logged_data)' + @crlf;
1482+ is_password_protected, is_snapshot, is_readonly, is_single_user, has_backup_checksums, is_damaged, ' + CASE WHEN @ProductVersionMajor >= 12
1483+ THEN + N ' encryptor_type, has_bulk_logged_data)' + @crlf
1484+ ELSE + N ' , has_bulk_logged_data)' + @crlf
1485+ END
1486+
14421487 SET @StringToExecute + = N'
14431488 SELECT database_name, database_guid, backup_set_uuid, type, backup_size, backup_start_date, backup_finish_date, media_set_id,
14441489 compressed_backup_size, recovery_model, server_name, machine_name, first_lsn, last_lsn, user_name, compatibility_level,
1445- is_password_protected, is_snapshot, is_readonly, is_single_user, has_backup_checksums, is_damaged, encryptor_type, has_bulk_logged_data' + @crlf;
1490+ is_password_protected, is_snapshot, is_readonly, is_single_user, has_backup_checksums, is_damaged, ' + CASE WHEN @ProductVersionMajor >= 12
1491+ THEN + N ' encryptor_type, has_bulk_logged_data)' + @crlf
1492+ ELSE + N ' , has_bulk_logged_data)' + @crlf
1493+ END
14461494 SET @StringToExecute + = N'
14471495 FROM msdb.dbo.backupset b
14481496 WHERE 1=1
0 commit comments