May 4, 2008 at 6:57 pm
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
May 4, 2008 at 9:36 pm
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
Change is inevitable... Change for the better is not.
May 4, 2008 at 11:41 pm
ohhh... ok thanks.. i guess my backup script will be stuck in the mssql format (dbname_db_YYYYDDMMHHMM.BAK) 🙂
"-=Still Learning=-"
Lester Policarpio
May 5, 2008 at 12:57 am
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
May 5, 2008 at 3:10 am
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
May 5, 2008 at 3:13 am
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
May 5, 2008 at 5:59 am
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 '
May 5, 2008 at 6:07 am
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
May 5, 2008 at 8:35 am
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... 🙂
May 5, 2008 at 9:23 am
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