Technical Article

Find Latest Backup

,

Just set the values of the variables

SET @BackupFolder = 'the folder'

SET @DatabaseName  'the database name'

EXEC sp_configure 'show advanced options' ,1
RECONFIGURE 
EXEC sp_configure 'xp_cmdshell',1
RECONFIGURE

SET NOCOUNT ON

DECLARE @BackupFolder VARCHAR (2000)
DECLARE @DatabaseName VARCHAR (200)
DECLARE @Command VARCHAR(100)
SET @Command = 'dir '+ @BackupFolder +'*.bak /b /s '

DECLARE @FilesFolder TABLE (FileNames VARCHAR(500))
INSERT INTO @FilesFolder
EXEC MASTER..xp_cmdshell @Command

SELECT max(FileNames) as 'backup' FROM @FilesFolder
WHERE FileNames like ''+ @DatabaseName +'' 

EXEC sp_configure 'show advanced options' ,0
RECONFIGURE

Rate

5 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (1)

You rated this post out of 5. Change rating