Command to know the Name of the database of a backup file

  • Hi GudAM just want to ask if there are any sql command/s to see the database name of a backup file? for example I have a database named Lester and the backup file of that database is backupDB_db_200805050856.BAK using tsql can i view the backupfile (using some sort of sql command) and it will output Lester as its database name?

    Any help is fully appreciated Thanks...

    "-=Still Learning=-"

    Lester Policarpio

  • In short... no. There's no command available to get a backup file to identify the database(s) that have been backed up in the file.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • ohhh... ok thanks.. i guess my backup script will be stuck in the mssql format (dbname_db_YYYYDDMMHHMM.BAK) 🙂

    "-=Still Learning=-"

    Lester Policarpio

  • If you do a Restore Headeronly, you get a resultset with details on each backup that's contained within the file. The DB name is one of the things returned.

    restore headeronly FROM DISK = '<Full path and name of backup file>'

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Woah!!!! thank you very much this is indeed helpfull I'll try to modify my script tomorrow. I'm almost hopeless for this one.

    "-=Still Learning=-"

    Lester Policarpio

  • Note it's a resultset, so it's going to be difficult to get into a variable, unless you do something like this.

    insert into SomeTable

    execute ('Restore .... ')

    select @SomeVar = [Database] From SomeTable ....

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hmm, why not this?

    use msdb

    select

    database_name

    from

    backupmediafamily f

    inner join backupset s on s.backup_set_id = f.media_set_id

    where

    physical_device_name = 'backupDB_db_200805050856.BAK '

  • Yup. That will work great if the backup was created on the server where the query is being run.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (5/5/2008)


    Yup. That will work great if the backup was created on the server where the query is being run.

    Got to watch out for MSDB history purges too...

    Your friendly High-Tech Janitor... 🙂

  • MSDB works, but it's not reliable for reasons mentioned above (needs to be same server, can be purged, etc)

    What are you trying to achieve?

Viewing 10 posts - 1 through 9 (of 9 total)

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