Latest File in Backup

  • I have 4 backup files and I would like to get the latest backup file from the drive how should I write in the script to pick the latest time stamp files in the code.

    (One_backup_200804181014.bak' )

    I need to execute this from JOB.

    RESTORE DATABASE [One_read] FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\One\One_backup_200804181014.bak' WITH FILE = 1,

    NOUNLOAD, REPLACE, STATS = 10

    GO

  • One way of doing it (not necessarily the most efficient or most secure) is to use xp_cmdshell to run the dir command in the folder your backup files are in. You will then have a list of files with dates which you can put in a temp table and organise as required. If you're familiar with SSIS then I'd say it would probably be better to develop a package to do the whole process for you.

    John

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply