Я знаю, что ОП использовал 2008 , но мы все перешли на несколько лет, и я просто написал сохраненный процесс для 2014 , который выбирает DatabaseBackupLSN
,так думал, что поделюсь ...
CREATE PROCEDURE [Utilities].[GetDatabaseBackupLsn]
(
@filePath VARCHAR(1000),
@databaseBackupLsn NUMERIC(25, 0) OUT
)
AS
BEGIN
DECLARE @backupInfo TABLE
(
BackupName nvarchar(128),
BackupDescription nvarchar(255),
BackupType smallint,
ExpirationDate datetime,
Compressed bit,
Position smallint,
DeviceType tinyint,
UserName nvarchar(128),
ServerName nvarchar(128),
DatabaseName nvarchar(128),
DatabaseVersion int,
DatabaseCreationDate datetime,
BackupSize numeric(20, 0),
FirstLSN numeric(25, 0),
LastLSN numeric(25, 0),
CheckpointLSN numeric(25, 0),
DatabaseBackupLSN numeric(25, 0),
BackupStartDate datetime,
BackupFinishDate datetime,
SortOrder smallint,
[CodePage] smallint,
UnicodeLocaleId int,
UnicodeComparisonStyle int,
CompatibilityLevel tinyint,
SoftwareVendorId int,
SoftwareVersionMajor int,
SoftwareVersionMinor int,
SoftwareVersionBuild int,
MachineName nvarchar(128),
Flags int,
BindingId uniqueidentifier,
RecoveryForkId uniqueidentifier,
Collation nvarchar(128),
FamilyGUID uniqueidentifier,
HasBulkLoggedData bit,
IsSnapshot bit,
IsReadOnly bit,
IsSingleUser bit,
HasBackupChecksums bit,
IsDamaged bit,
BeginsLogChain bit,
HasIncompleteMetaData bit,
IsForceOffline bit,
IsCopyOnly bit,
FirstRecoveryForkID uniqueidentifier,
ForkPointLSN numeric(25, 0),
RecoveryModel nvarchar(60),
DifferentialBaseLSN numeric(25, 0),
DifferentialBaseGUID uniqueidentifier,
BackupTypeDescription nvarchar(60),
BackupSetGUID uniqueidentifier,
CompressedBackupSize bigint,
Containment tinyint,
KeyAlgorithm nvarchar(32),
EncryptorThumbprint varbinary(20),
EncryptorType nvarchar(32)
)
DECLARE @sql NVARCHAR(1100)
SET @sql = N'RESTORE HEADERONLY FROM DISK = ''' + @filePath + ''''
INSERT @backupInfo
EXEC(@sql)
SELECT @databaseBackupLSN = DatabaseBackupLSN
FROM @backupInfo
END
Документы RESTORE HEADERONLY
здесь .
Пример использования:
DECLARE @databaseBackupLsn NUMERIC(25, 0)
EXEC GetDatabaseBackupLsn
'd:\transfer\YourDatabaseBackup_2015_07_09_05_31_59.bak',
@databaseBackupLsn OUT
SELECT @databaseBackupLsn
Обновление 18/02/2016 : SQL Server 2014 с пакетом обновления 1 добавил 3 новых столбца к выводу RESTORE HEADERONLY
: KeyAlgorithm
EncryptorThumbprint
EncryptorType
.Я добавил эти столбцы в процедуру выше.