Skip to content

Commit

Permalink
Update sp_DatabaseRestore.sql
Browse files Browse the repository at this point in the history
fixed ticket 3156 sp_databaserestore don't see backups which consists of more than 10 backupfiles when using @StoPAt
  • Loading branch information
wfvdijk committed Nov 28, 2022
1 parent ebec3dd commit f812b71
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions sp_DatabaseRestore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -636,15 +636,19 @@ BEGIN
/*End folder sanity check*/

IF @StopAt IS NOT NULL
BEGIN
DELETE
FROM @FileList
WHERE BackupFile LIKE N'%.bak'
AND
BackupFile LIKE N'%' + @Database + N'%'
AND
(REPLACE( RIGHT( REPLACE( BackupFile, RIGHT( BackupFile, PATINDEX( '%_[0-9][0-9]%', REVERSE( BackupFile ) ) ), '' ), 16 ), '_', '' ) > @StopAt);
END
BEGIN
DELETE
FROM @FileList
WHERE BackupFile LIKE N'%[_][0-9].bak'
AND BackupFile LIKE N'%' + @Database + N'%'
AND (REPLACE( RIGHT( REPLACE( BackupFile, RIGHT( BackupFile, PATINDEX( '%_[0-9][0-9]%', REVERSE( BackupFile ) ) ), '' ), 16 ), '_', '' ) > @StopAt);

DELETE
FROM @FileList
WHERE BackupFile LIKE N'%[_][0-9][0-9].bak'
AND BackupFile LIKE N'%' + @Database + N'%'
AND (REPLACE( RIGHT( REPLACE( BackupFile, RIGHT( BackupFile, PATINDEX( '%_[0-9][0-9]%', REVERSE( BackupFile ) ) ), '' ), 18 ), '_', '' ) > @StopAt);
END;

-- Find latest full backup
SELECT @LastFullBackup = MAX(BackupFile)
Expand Down

0 comments on commit f812b71

Please sign in to comment.