RESTORE HEADERONLY FROM DISK ServerName column - sql-server

I've a LocalDB instance (localdb)\foo (version 12.0.6024.0) and a database called myDB.
I backup the database and perform this query: RESTORE HEADERONLY FROM DISK = 'C:\\myDB.bak';
In ServerName column is not (localdb)\foo as expected.
How to get the original ServerName from the BAK file?
Or to decode the displayed one?

Related

How to restore data from single bak file which contain multiple mdf file in 2008R2

i have multiple mdf files inside a single bak file how can I restore bak file in database.
you can run that command to see the file list of your bak file:
RESTORE FILELISTONLY FROM DISK ='<path>\<yourfile.bak>'
After you see the files you can build a restore command like that (just as sample):
restore database [db_name] from disk = '<file>.bak'
with
move '<data_file_name>' to 'D:\MSSQL\Data\<file>.mdf',
move '<log_file_name>' to 'D:\MSSQL\Data\<file>.ldf'
Run restore headeronly to list the backup sets in the file (device), then restore filelistonly to see the details of the backup set you want to restore, then restore database targeting the selected backup set.
--create the backup file
backup database adventureworks2017 to disk='c:\temp\aw.bak' with format, init
--append some more backups to the file
backup database adventureworks2017 to disk='c:\temp\aw.bak'
backup database adventureworks2017 to disk='c:\temp\aw.bak'
restore headeronly from disk='c:\temp\aw.bak'
restore filelistonly from disk='c:\temp\aw.bak' with file=2
restore database adventureworks2017 from disk='c:\temp\aw.bak' with file=2

no backup selected for restore sql server 2012

I am trying to restore db from my db backup file when i select and add the db .bak file
I have seen that error "No back upset selected to be restored"
I also tried from script to restore it but failed.
kindly tell me some effective way to do that??
I have already tried this but failed
RESTORE DATABASE <Your Database>
FROM DISK='<the path to your backup file>\<Your Database>.bak'
Try RESTORE HEADERONLY to see if there are several backup sets in your bak file
RESTORE HEADERONLY
FROM DISK='<the path to your backup file>\<Your Database>.bak'
http://msdn.microsoft.com/en-us/library/ms178536.aspx
and if there are several sets, choose the one you want :
RESTORE DATABASE <Your Database>
FROM DISK='<the path to your backup file>\<Your Database>.bak'
WITH FILE = <you set number>;

Restore MSSQL database backup to a new database

I need to make clean database template backup and then generate a new one database with another name, but with backuped content.
Backup script is:
sqlcmd -S %DB_HOST% -Q "BACKUP DATABASE %DB_NAME% TO DISK = '%BACKUP_FILE%'"
Restore script is:
sqlcmd -S %DB_HOST% -Q "RESTORE DATABASE %DB_NAME% FROM DISK = '%BACKUP_FILE%' WITH REPLACE"
And it works on the same database name.
But if i backup DB 'ORIGINAL_DB_NAME' and then restore it to 'NEW_DB_NAME' it will raise exception:
Msg 1834, Level 16, State 1, Server <HOST>, Line 1
The file '.....\MSSQL\Data\ORIGINAL_DB_NAME.mdf' cannot be overwritten. It is being used by database 'ORIGINAL_DB_NAME'.
....
You need to specify a new location for the data/log files.
See this MSDN article, Example D
RESTORE DATABASE AdventureWorks2012
FROM AdventureWorksBackups
WITH NORECOVERY,
MOVE 'AdventureWorks2012_Data' TO
'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\NewAdvWorks.mdf',
MOVE 'AdventureWorks2012_Log'
TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\NewAdvWorks.ldf';
RESTORE LOG AdventureWorks2012
FROM AdventureWorksBackups
WITH RECOVERY;
You can also avoid that conundrum using SSMS. Under the Options tab, after you have selected a source for your restore direct the data and log files to either the files you want to overwrite, or point them to the directory you need and name them appropriately.
If you go to Files on the Restore Configuration, make sure that the Original File Name is not the same as Restore As, that should solve your issue.

Backup file's database

I use Sql Server 2005.
I wanna write code for restore a backup file, and I need to know what is database's name that backup file belongs to it.
How can I know?
I think the closest you can get is restore filelistonly ...
RESTORE FILELISTONLY From DISK = 'C:\temp\mybackup.bak' with file = 1
This returns data and the LogicalName field is the SQL Filename of File 1 in the database before it was backed up

VB.NET restore Backup file created on one server to another server

i am using SQL server express 2005 as an backend. I created a backup file programmatically.If i use same server , then it restore the data successfuly. however if we try to restore on different server, then it fails. and throw following message
"The Backup set Holds a backup of a database other than the existing 'DatabaseName' database. RESTORE DATABASE is terminating abnormally."
On both server, Sql server instance name and database name is same.
Please suggest how can i resolve this error
You need to RESTORE from files (which are contained in the backup set) rather than the backup set directly. The bottom example is to copy a database, but the idea is the same.:
BACKUP DATABASE AdventureWorks
TO AdventureWorksBackups ;
RESTORE FILELISTONLY
FROM AdventureWorksBackups ;
RESTORE DATABASE TestDB
FROM AdventureWorksBackups
WITH MOVE 'AdventureWorks_Data' TO 'C:\MySQLServer\testdb.mdf',
MOVE 'AdventureWorks_Log' TO 'C:\MySQLServer\testdb.ldf';
GO

Resources