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

  • satnam.singh 44358

    Ten Centuries

    Points: 1214

    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

     

     

     

  • crow1969

    SSCrazy

    Points: 2757

    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 1 week, 5 days ago by  crow1969. Reason: Tried to clean up code tags

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

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