I have a database called 'AdvWorks'.
I have a backup call 'BackupDB.bak'.
When I restore the BackupDB.bak over AdvWorks, SQL tries to overwrite the data files of the BackupDB rather than the AdvWorks data files. I have to change this everything and to me this makes no sense.
Can someone please tell me why it behaves like this?
And secondly, can this default location be changed to the restore db files rather than the backup db files?
Thanks.
, SQL tries to overwrite the data files of the BackupDB rather than the AdvWorks data files
This is because,the location is also copied in backup file
To overcome this,use RESTORE WITH MOVE..
RESTORE DATABASE MyNwind
FROM MyNwind_1
WITH NORECOVERY,
MOVE 'MyNwind_data_1' TO 'D:\MyData\MyNwind_data_1.mdf',
MOVE 'MyNwind_data_2' TO 'D:\MyData\MyNwind_data_2.ndf';
Related
I have a .bak file called PublishingEngine_03102019.bak. I would like to restore this back twice, once to a DB called PublishingEngine (the original name of the source database) and again to a DB called PublishingEngine_Dev.
I can do the original restore just fine. I now have a DB called PublishingEngine. Now I'm trying to do the second backup. But I get this error:
Exclusive access could not be obtained because the database is in use
I've changed the name of the database in the Destination Database field. Do I need to change it anyplace else?
In the Options page check "Close existing connections to destination database".
In the option section in restoring wizard change the name of the ldf and mdf files or set other directory rather than the default ones..i guess it will solve the problem..
I ended up renaming the existing database first, and then the second restore ran w/o a problem.
I am testing to see if a SQL Server server based program can also work on AWS Cloud Server with 2016 SQL Server on the Amazon server. In order for me to test it, I need to restore 2 databases.
The first one eventually restored fine once i figured it out...restoring the database from my S3 "bucket" BAK file.
So then I tried to restore the 2nd database, using the same restore stored proceudre, and get this message:
[2017-12-28 02:44:22.320] The file 'D:\rdsdbdata\DATA\smsystemdata.mdf' cannot be overwritten. It is being used by database 'amwsys'.
[2017-12-28 02:44:22.320] File 'sm_system_data' cannot be restored to 'D:\rdsdbdata\DATA\smsystemdata.mdf'. Use WITH MOVE to identify a valid location for the file.
I can't find where to use the WITH MOVE because it won't let me restore it interactively through the Management Studio restore menu; instead I have to give it a stored procedure command:
exec msdb.dbo.rds_restore_database
#restore_db_name='sample99',
#s3_arn_to_restore_from='arn:aws:s3:::lighthouse-chicago/sample999.bak';
And each time it tells me it can't restore it because it's going to overwrite the first database's files.
Much thanks
bill
I think you are stuck in RDS's restriction.
I had the similar problem as you. Multiple restore from one DB instance is impossible at RDS.
Here is RDS's restriction you may encounter.
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html
You can't restore a backup file to the same DB instance that was used
to create the backup file. Instead, restore the backup file to a new
DB instance. Renaming the database is not a workaround for this
limitation.
You can't restore the same backup file to a DB instance multiple
times. That is, you can't restore a backup file to a DB instance that
already contains the database that you are restoring. Renaming the
database is not a workaround for this limitation.
If you are in this case, you can't use .BAK file. To avoid it, you should create DB instance with DML and import table data.
As the title says I cannot browse and cannot see backup folder.
is there any other way to restore bak file ? or how can I fix this ?
Try this query
RESTORE DATABASE Databasename
FROM DISK = 'Z:\SQLServerBackups\tms.bak' ;
The backup runs with the file permissions of the id running SQL Server. So, you need to either:
Move the file to a location SQL Server has access to. The default backup location is always a safe bet.
Grant permissions to the account running SQL to see the file.
If using a mapped drive, this is more difficult. First, the mapping won't apply so use a fully qualified path name (e.g. \server\path\backupfile.bak) instead of the drive letter. Second, make sure the permissions are correct.
I've got a bak file (which is a backup database file for a SQL server express 2005 mdf file) and I should obtain the MDF file so that I can work on its tables, how can I get the original MDF file from this bak file? I'm using Visual Studio 2012, is it necessary to have management studio? I've tried to restore this bak file to an empty database in another system containing Sql server express management studio 2008, but it says databases don't match, what is going wrong?
Keep in mind that restoring a database backup file will not give the original MDF (and LDF) files. The only way to get the original MDF file is to copy it
You can execute the T-SQL suggested by steoleary in Visual Studio, see more here: How to: Run SQL Scripts in Solution Explorer. You can also do that in SQL Server management Studio.
The blank database you created doesn't help much, unless you want to synchronize the backup to it. But for that you would need a 3rd party tool
First, execute the following to find out the logical file names in your backup. This example is for the backup named TestFull.bak stored in E:\Test
RESTORE FILELISTONLY
FROM DISK = 'E:\Test\TestFull.bak'
GO
The logical names should be used in the next script. Also, update the paths and names used
RESTORE DATABASE YourDB
FROM DISK = 'E:\Test\TestFull.bak'
WITH MOVE 'test1' TO 'E:\test\TestMDFFile.mdf',
MOVE 'test1_log' TO 'E:\test\TestLDFFile.ldf'
If you have created a blank database, to overwrite this with the backup you will need to specify the WITH REPLACE parameter.
Also, you may have to specify the MOVE parameter to put the files into the correct locations.
You should be able to quite easily find these options in the GUI when doing the restore, or alternatively you can script it out by using the reference here:
How to: Restore a Database to a New Location and Name (Transact-SQL)
I have a series of repetitive tasks here at work. One of these is the creation of new database from a template.
To achieve this we have a *master_db* database that act like a template and its location is something like C:\Backup\master_db.bak.
After the creation of a new database new_db, right-click on it and go through Task->Restore->Database. In the General tab I choose From device and then I set C:\Backup\master_db.bak as restoring source. In the Options tab I'll choose Overwrite existing database and I also need to change .mdf and .log file (currently C:\SQLData\master_db.mdf and C:\SQLData\master_db_log.ldf in C:\SQLData\new_db.mdf and C:\SQLData\new_db_log.ldf).
This iter is in working order but for automation sake I need to do this step through code. What should I do? What parameters needs my RESTORE command? What command should I use to properly set .mdf and .ldf files?
restore database new_db from disk = 'C:\Backup\master_db.bak'
with
move '<data_file>' to 'C:\SQLData\new_db.mdf',
move '<log_file>' to 'C:\SQLData\new_db_log.ldf',
replace
You need to update <data_file> and <log_file> with the logical file names for these files. You should be able to see them in the GUI.