How to fetch Latest File from Disk based upon the DateTime in the FileName.

  • Can anybody please advise on How can we fetch the list of files present in a location based upon the DateTime in it.

    For e.g:-

    If there are following files present on the disk:-

    master_full_backup_20190701.bak

    master_full_backup_20190702.bak

    master_full_backup_20190703.bak

    model_full_backup_20190701.bak

    model_full_backup_20190702.bak

    model_full_backup_20190703.bak

    I want to extract only the master and model backups taken on 1 July 2019 i.e. which has following data appended to it _20190701

     

     

     

  • Better than looking at the file list would be to look at the backup tables in the msdb database.

     

    use msdb;

    select bs.Database_name, bs.user_name, bs.backup_start_date, bs.type, bmf.physical_device_name

    from backupset bs join

    backupmediafamily bmf on bs.media_set_id = bmf.media_set_id

    where bs.database_name = 'master'

    order by bs.backup_start_date desc

    • This reply was modified 4 years, 9 months ago by  crow1969. Reason: Tried to clean up code tags

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

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