When restoring my database i have a problem with the physical file of the full text catalog being in use.
The file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\FTData\MyCatalog' cannot be overwritten. It is being used by database 'demo2'.
I use this restore statement
RESTORE database demo from disk = N'c:\temp\demo.bak' WITH REPLACE
,MOVE 'demo_Data' TO 'd:\Program Files\Microsoft SQL Server 2005\MSSQL\Data\demo.MDF'
,MOVE 'demo_Log' TO 'd:\Program Files\Microsoft SQL Server 2005\MSSQL\Data\demo.LDF';
A solution would be to restore without the full text catalog, but i can's figure out how to do that.
I have had to restore databases with full-text as well (in fact, fixed my auto-restore script to auto-restore full-text index as well)
I don't know any way to NOT restore them (SQL restore will give you an error if you don't specify RESTORE WITH MOVE for the full-text index, unless there is a path that matches the original path inside the .bak file)
I suggest
restore the entire database, including full-text index
delete all full-text index inside the database
enumerate all full-text catalogs
SELECT name FROM DB.sys.fulltext_catalogs (SQL2005/2008)
then generate the drop command (you may have to drop the index on the tables before dropping the catalogs)
DROP FULLTEXT CATALOG [name]
I'm not sure how to restore without fulltext file but you can always restore with move. You are doing it already for database and log file, just complete your statement with:
,MOVE 'sysft_demo_ft' TO 'd:\NewLocationForFullTextFile.ft'
You can get the exact names of the files with:
RESTORE FILELISTONLY
FROM DISK='C:\yourbackupfile.bak'
Related
I am using SSMS 2017 and attempting to restore a SQL Server 2016 backup (.bak) file to a new database (the data file and log file names in the original backup are different from the new database I am restoring to), so for example, db1.bak is being used to create a new database called db2 through a restore operation.
After the restore completes, all stored procedures and views are present, but none of the tables are there.
These are the steps I've taken in SSMS to perform the restore:
Right click the Databases folder
Select "Restore Database"
Under the General Page: For "Source" I choose Device and select the db1.bak file, and for "Destination" I enter the name of the new database to be created from the backup (db2)
Under the Files Page I select Relocate all files to folder (both Data and Log folder paths have been pre-populated with the correct names) as have the Logical File Name and the Restore As paths.
Under the Options Page I either select nothing or select Overwrite the existing database (WITH REPLACE).
Once the restore completes "successfully" I expand the newly created db2 and click to expand the tables and receive this error message:
What am I doing wrong?
Here is the script:
USE [master]
RESTORE DATABASE [PdsClone] FROM DISK = N'F:\SQLBackups\PDS_backup_2017_12_12_001015_0199267.bak' WITH FILE = 1, MOVE N'PDS_Data' TO N'E:\Program Files\Microsoft SQL Server\MSSQL13.PDS\MSSQL\DATA\PdsClone.mdf', MOVE N'PDS_Log' TO N'E:\Program Files\Microsoft SQL Server\MSSQL13.PDS\MSSQL\DATA\PdsClone_log.ldf', NOUNLOAD, REPLACE, STATS = 5 GO
UPDATE
I had the server group add another disk to that server and moved the SQL backups there, and I was able to successfully complete the restore this morning. I had previously cleaned off most of the backup files, but could it have been a space issue that prevented the tables from showing up in the restore? Every try it indicated success but no tables. They are there now, and I am thankful for your suggestions and help!
Not really an answer to what happened, but perhaps SSMS was doing something a little buggy as #JeroenMostert suggested.
I am trying to restore a db with a backup, but it fails each time because of a file in use. The file is ftrow_FTC{xxxxxxx}.ndf
Does anyone know what this file is and what its for? Do I need it? If not, how can I get rid of it? Thank you.
I should add, this is SQL 2012 server on a Server 2008 R2.
the ftrow_FTC{xxxxxxx}.ndf if a Full-Text Catalog file. You're probably using SQL Server Management Studio wizard to restore that database. However, you can also use a t-sql command to do the restore.
In the latter case you could tell SQL Server to restore your full text catalog file under different name/path with the RESTORE ... WITH MOVE command:
RESTORE DATABASE DBNAME from disk = N'd:\path\to\your\backup.bak'
WITH MOVE 'ftrow_FTC{xxxxxxx}.ndf' TO 'd:\path\to\new\FT_location\ftrow_FTC{xxxxxxx}.ndf'
replace the DBNAME with your real DB name and the ftrow file name with real file name.
UPDATE: you can also easily restore your DB with full text catalog under different file name using SQL Server Management Studio dialog. During restore simply locate your ftrow file record in the DB files list and assign it to different path. That way you will not get conflict with the ftrow file used by your live DB.
HTH
I have a probleme while restoring my database from a .bak file. If I use sql query line I'll find the database but with no table in it, and if I use restoring wizard with the same file and the default configuration i'll get my database and my tables. I think that I'm missing something in this query:
first query
RESTORE DATABASE ColisageTest
FROM DISK = 'e:\colisageTest.bak'
second query
RESTORE DATABASE ColisageTest
FROM DISK = 'e:\colisageTest.bak'
WITH REPLACE,
MOVE 'ColisageTest' TO 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.COLISAGE\MSSQL\DATA\ColisageTest.mdf',
MOVE 'ColisageTest_log' TO 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.COLISAGE\MSSQL\DATA\ColisageTest_log.ldf'
GO
third query
RESTORE DATABASE ColisageTest
FROM DISK = 'e:\colisageTest.bak'
with RECOVERY;
GO
No one of them is working all of them it just restore my database but no tables
Are you sure the database is not empty on tables?
One way to test this is to make another .bak file (that you know have tables) and try to restore it for validation.
No problem with empty tables I'm saying you might have an empty database, ie there is no table there at all.
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 file with .bak extension.
How can I import this date to a database in SQL Server?
On SQL Server Management Studio
Right click Databases on left pane (Object Explorer)
Click Restore Database...
Choose Device, click ..., and add your .bak file
Click OK, then OK again
Done.
This will show you a list of database files contained in DB.bak:
RESTORE FILELISTONLY
FROM DISK = 'D:\3.0 Databases\DB.bak'
You will need the logical names from that list for the MOVE operation in the second step:
RESTORE DATABASE YourDB
FROM DISK = 'D:\3.0 Databases\DB.bak'
and you have to move appropriate mdf,ndf & ldf files using
With Move 'primarydatafilename' To 'D:\DB\data.mdf',
Move 'secondarydatafile' To 'D:\DB\data1.ndf',
Move 'logfilename' To 'D:\DB\log.ldf'
You can simply restore these database backup files using native SQL Server methods, or you can use ApexSQL Restore tool to quickly virtually attach the files and access them as fully restored databases.
Disclaimer: I work as a Product Support Engineer at ApexSQL
Instead of choosing Restore Database..., select Restore Files and Filegroups...
Then enter a database name, select your .bak file path as the source, check the restore checkbox, and click Ok. If the .bak file is valid, it will work.
(The SQL Server restore option names are not intuitive for what should a very simple task.)
On Microsoft SQL Server Management Studio 2019:
On Restore Database window:
Choose Device
Choose Add and pick target file
OK to confirm
OK to confirm restore
Connect to a server you want to store your DB
Right-click Database
Click Restore
Choose the Device radio button under the source section
Click Add.
Navigate to the path where your .bak file is stored, select it and click OK
Enter the destination of your DB
Enter the name by which you want to store your DB
Click OK
Done
Although it is much easier to restore database using SSMS as stated in many answers.
You can also restore Database using .bak with SQL server query, for example
RESTORE DATABASE AdventureWorks2012 FROM DISK = 'D:\AdventureWorks2012.BAK'
GO
In above Query you need to keep in mind about .mdf/.ldf file location.
You might get error
System.Data.SqlClient.SqlError: Directory lookup for the file "C:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL.1\MSSQL\DATA\AdventureWorks.MDF" failed with the operating system error 3(The system cannot find the path specified.). (Microsoft.SqlServer.SmoExtended)
So you need to run Query as below
RESTORE FILELISTONLY
FROM DISK = 'D:\AdventureWorks2012.BAK'
Once you will run above Query you will get location of mdf/ldf use it Restore database using query
USE MASTER
GO
RESTORE DATABASE DBASE
FROM DISK = 'D:\AdventureWorks2012.BAK'
WITH
MOVE 'DBASE' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.DBASE\MSSQL\DATA\DBASE.MDF',
MOVE 'DBASE_LOG' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.DBASE\MSSQL\DATA\DBASE_1.LDF',
NOUNLOAD, REPLACE, NOUNLOAD, STATS = 5
GO
Source:Restore database from .bak file in SQL server (With & without scripts)
Simply use
sp_restoredb 'Your Database Name' ,'Location From you want to restore'
Example: sp_restoredb 'omDB','D:\abc.bak'
You can use node package, if you often need to restore databases in development process.
Install:
npm install -g sql-bak-restore
Usage:
sql-bak-restore <bakPath> <dbName> <oldDbName> <owner>
Arguments:
bakpath, relative or absolute path to file
dbName, to which database to restore (!! database with this name will be deleted if exists !!)
oldDbName, database name (if you don't know, specify something and run, you will see available databases after run.)
owner, userName to make and give him db_owner privileges (password "1")
!! sqlcmd command line utility should be in your PATH variable.
https://github.com/vladimirbuskin/sql-bak-restore/