@@ -690,13 +690,15 @@ BEGIN
690
690
END ;
691
691
692
692
-- Find latest full backup
693
- SELECT @LastFullBackup = MAX (BackupFile)
693
+ -- Get the TOP record to use in "Restore HeaderOnly/FileListOnly" statement as well as Non-Split Backups Restore Command
694
+ SELECT TOP 1 @LastFullBackup = BackupFile, @CurrentBackupPathFull = BackupPath
694
695
FROM @FileList
695
696
WHERE BackupFile LIKE N ' %.bak'
696
697
AND
697
698
BackupFile LIKE N ' %' + @Database + N ' %'
698
699
AND
699
- (@StopAt IS NULL OR REPLACE ( RIGHT ( REPLACE ( @LastFullBackup, RIGHT ( @LastFullBackup, PATINDEX ( ' %_[0-9][0-9]%' , REVERSE ( @LastFullBackup ) ) ), ' ' ), 16 ), ' _' , ' ' ) <= @StopAt);
700
+ (@StopAt IS NULL OR REPLACE ( RIGHT ( REPLACE ( BackupFile, RIGHT ( BackupFile, PATINDEX ( ' %_[0-9][0-9]%' , REVERSE ( BackupFile ) ) ), ' ' ), 16 ), ' _' , ' ' ) <= @StopAt)
701
+ ORDER BY BackupFile DESC ;
700
702
701
703
/* To get all backups that belong to the same set we can do two things:
702
704
1. RESTORE HEADERONLY of ALL backup files in the folder and look for BackupSetGUID.
@@ -736,11 +738,6 @@ BEGIN
736
738
SET @FileListParamSQL + = N ' )' + NCHAR (13 ) + NCHAR (10 );
737
739
SET @FileListParamSQL + = N ' EXEC ('' RESTORE FILELISTONLY FROM DISK='' '' {Path}'' '' '' )' ;
738
740
739
- -- get the TOP record to use in "Restore HeaderOnly/FileListOnly" statement as well as Non-Split Backups Restore Command
740
- SELECT TOP 1 @CurrentBackupPathFull = BackupPath, @LastFullBackup = BackupFile
741
- FROM @FileList
742
- ORDER BY REPLACE ( RIGHT ( REPLACE ( BackupFile, RIGHT ( BackupFile, PATINDEX ( ' %_[0-9][0-9]%' , REVERSE ( BackupFile ) ) ), ' ' ), 16 ), ' _' , ' ' ) DESC ;
743
-
744
741
SET @sql = REPLACE (@FileListParamSQL, N ' {Path}' , @CurrentBackupPathFull + @LastFullBackup);
745
742
746
743
IF @Debug = 1
0 commit comments