how can i restore my database with new name - sql-server

I have a backup file from my main DB(IDTDB) that called MainDBBackup.bak and i want to restore it with another name.but i recieve this error:
"the logical file 'IDTDB_Log' is not part of database 'newDB'.use RESTORE FILELISTONLY to list logical file names.restore database terminated abnormally.change database context to master."
i used this code to restore my database:
"use master;restore filelistonly from disk=N'my backup file path'; restore database newDB from disk=N'my backup file path' with file=1,replace,nounload,stats=10;"
note: it is important for me to have a new database with new name.
i have created a new database and its tables by execute a sql query and tried to restore my mainDB to it but i recieved that error again.

Using SSMS you can create a new database and then restore to that from your backup. You will need to set the option overwrite existing database.

Related

RESTORE database with different name Fails - "The backup set holds a backup of a database other than the existing"

I have database backup A.bak
I want to restore that backup file, using the SQL Server Management Studio, into database B which has all the same tables/columns but just different name.
If I try to do the restore - I am getting error:
The backup set holds a backup of a database other than the existing
How can I resolve this? I tried renaming the .bak file but it didn't work
Specify the "Overwrite the existing database (WITH REPLACE)" option:

Import database backup (.bak file) into another database

I'm using microsoft SQL server. I have a database that we can call database1 and its backup in .bak format.
I need to restore the backup to another, blank database that we can call database_temp, so both database must exist. I need to get and confirm some data from the database_temp archive and then delete it when I'll end my job.
what I did:
1) created new database "database_blank"
2) tasks - restore database. In source I choose "device" and then my .bak file, in destination I select database_temp.
3) in option I choose Overwrite the existing database with replace.
I got the error "Restore of database failed the file cannot be overwritten it is being used by database1 database"
You have to move the database files.
e.g.
RESTORE DATABASE [AdventureWorks] FROM DISK = 'c:\backup\Adv.bak'
WITH CHECKSUM,
MOVE 'AdventureWorks_Data' TO 'c:\mssql\data\AdventureWorksCopy_Data.mdf',
MOVE 'AdventureWorks_Log' TO 'c:\mssql\log\AdventureWorksCopy_Log.ldf',
RECOVERY, REPLACE, STATS = 10;
The first part of the move is the logical file name of the database file. Right click on the original database - Properties - Files to get the right names.
The full documented syntax can be found here

Restore DB2 backup to another DB2 database with different name

I have a DB2 10 database backup file that I would like to restore to another environment. The problem is that the database has been setup with a different name and the restore complains because the database names are different.
Is there a way to restore the database backup file to the other environment?
Thanks
Here is the command I used to restore:
db2 "RESTORE DATABASE <restore database name> FROM <current restore directory> TAKEN AT <timestamp of full backup> TO <Local database directory> INTO <new database name>"
Example:
Database name of original backup is:
SYSTEM
My backup directory is:
/db2inst1/archive/backup/SYSTEM/level0/
Timestamp of original backup is:
20180503141925
Local database directory is: I would redirect this directory to your database standard list
New database name is:
SYSTEM2
Example output command is:
db2 "RESTORE DATABASE system FROM /db2inst1/archive/backup/SYSTEM/level0/ TAKEN AT
20180503141925 TO /db2inst1/ INTO system2"
Once complete roll-forward database:
db2 "ROLLFORWARD DB SYSTEM2 TO END OF LOGS AND COMPLETE"
You can use the "redirected" restore option by generating a file
db2 restore database mydb redirect generate script restore.sql
Once the script is generated, you can change the names, file locations, etc.
And finally, execute the script
db2 -tvf restore.sql
Thanks for the help.
In the end we dropped the existing database, restored the database from the backup file and then renamed the restored database to match the previous database name

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>;

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