I am trying to restore a *.bak file from a SQL 2012 DB and am having a lot of trouble. There appears to be similar questions that are unanswered so I'm hoping the below elaborates on the issue.
Use the below to get the logical names for the database and log
RESTORE FILELISTONLY
FROM disk = 'C:\Users\jonathan\Desktop\mydb_Full.bak'
Run the below to restore
RESTORE DATABASE mydb
FROM disk = 'C:\Users\jonathan\Desktop\mydb_Full.bak'
WITH RECOVERY,
MOVE 'mydb' TO
'C:\Users\jonathan\mydb.mdf',
MOVE 'mydb_log'
TO 'C:\Users\jonathan\mydb_log.ldf'
Get the error:
Processed 448 pages for database 'mydb', file 'mydb' on file 1.
Processed 2 pages for database 'mydb', file 'mydb_log' on file 1.
Msg 1853, Level 16, State 1, Line 5
The logical database file 'mydb_log' cannot be found. Specify the full path for the file.
Msg 3167, Level 16, State 1, Line 5
RESTORE could not start database 'mydb'.
Msg 3013, Level 16, State 1, Line 5
RESTORE DATABASE is terminating abnormally.
Suggestion from SO/Google is to try and detach then attach, the attach may initiate a upgrade process of some sort.
exec sp_detach_db mydb, 'true'
Error:
Msg 3707, Level 16, State 2, Line 17
Cannot detach a suspect or recovery pending database. It must be repaired or dropped.
Blogs suggest setting it to emergency mode:
ALTER DATABASE smsr4000 SET EMERGENCY;
This results in
Msg 823, Level 24, State 1, Line 20
The operating system returned error 5(Access is denied.) to SQL Server during a read at offset 0x00000000012000 in file 'C:\Users\jonathanchannon\mydb.mdf'. Additional messages in the SQL Server error log and system event log may provide more detail. This is a severe system-level error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.
So now I'm lost. How can I get this sql backup into LocalDB?
Thanks
UPDATE: There is an open MS issue here on connect and this blog post also look promising but when using sqlcmd to connect to an instance I get and error:
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Named Pipes Provider: Could not open a connection to SQL Server [2].
UPDATE 2: Finally gave up and installed SQL Express and Management Studio, worked first time.
I ran into the same issue when trying to script our use of LocalDB. However, there is one small detail that got me out of this rut.
First, you should attempt to restore the database and supply the new filenames (using the command RESTORE DATABASE mydb... ). After this, the correct MDF and LDF are mysteriously available in the proper location, despite the error.
After this, you have a few options. The first problem is that SQL will show the database stuck in a "Restoring..." state. This could be solved a few ways, probably. In my solution, I delete and recreate my LocalDB instance using the SqlLocalDb utility. If that's too heavy-handed, you could probably copy the MDF and LDF files, then drop the database instead. This command line stops, drops, and recreates the LocalDB instance named "v11.0":
sqllocaldb p v11.0 && sqllocaldb d v11.0 && sqllocaldb c v11.0 -s
At that point, I had an MDF and LDF that I could use. So, I used this to force it across the finish line:
CREATE DATABASE X ON (Name=X, Filename=X) LOG ON (Name=X, Filename=X) FOR ATTACH;
I ran into a similar issue and did the following to resolve it.
Steps I took:
restore from the backup (BAK) file to localdb
see where the mdf and ldf files went to (probably went to c:\users\yourid)
create new folders in a new area like C:\sql-data-files\data and C:\sql-data-files\log
copy the mdf to the data folder and ldf to the log folder
delete the new database that just appeared in your Databases list as a result of the above restore
then run this script in SQL Server Management Studio
CREATE DATABASE MyDatabase
ON (FILENAME = 'C:\sql-data-files\data\MyDatabase.mdf'),
(FILENAME = 'C:\sql-data-files\log\MyDatabase.ldf')
FOR ATTACH;
All of the above permitted me to bypass the many steps other sites were recommending.
Related
How to fix Recovery Pending State in SQL Server Database?
Execute the following set of queries:
ALTER DATABASE [DBName] SET EMERGENCY;
GO
ALTER DATABASE [DBName] set single_user
GO
DBCC CHECKDB ([DBName], REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS;
GO
ALTER DATABASE [DBName] set multi_user
GO
For more info: https://www.stellarinfo.com/blog/fix-sql-database-recovery-pending-state-issue/
When your Database .mdf file name is renamed, this issue is occurred. To solve:
Restart SQL EXPRESS in Services, Pending issue is solved.
In our case it was caused by the disk drive running out of space. We deleted some junk to free space, then fixed the "Recovery Pending" by stopping and restarting the SQL Server Service.
Detach, re-attach, solved !
ALTER DATABASE MyDatabase SET EMERGENCY;
EXEC sp_detach_db MyDatabase
EXEC sp_attach_single_file_db #DBName = MyDatabase, #physname = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\MyDatabase.mdf'
While using SQL Management Studio, there is an intermittent issue when a user is changing the Database Names then sometimes SQL Server uses the same DB file for two different Databases. If SQL Server is in this state then you would be probably seeing the following error if you try Mahesh's answer:
"The process cannot access the file because it is being used by another process"
To fix this issue:
Stop MSSQLServer service from the Services Console MMC
Rename the DB and the Log files (Database Properties -> Files)
In the Object Explorer window in SQL Management Studio, refresh the 'Databases Folder', if you see that there is another Database node (in addition to the one which you are trying to rectify this issue) which is shown in 'Recovery Pending State' then proceed to the next step. If you do not see this error then you need to try something else to resolve this issue
Make a backup of the DB and Log files for new offending node from step 3 and !!Careful!! delete the database
Restore the Db File names which you changed in Step 2
Now start the MSSQLServer service from the Services Console
Re-try the steps from Mahesh's answer
In my case, this affected the secondary server in a High Availability SQL Server cluster.
The primary was Synchronizing but the secondary was Recovery Pending.
After checking in cluadmin.msc, realised that the secondary server wasn't healthy in the cluster.
Then determined Cluster Service had failed to start on the second cluster box after a Windows Update enforced reboot (may have happened because the file share witness was rebooting after a similar Windows Update at the same time).
Starting the Cluster Service brought the databases back into Synchronizing status.
Ensure that the "Log On" account for the "SQL Server (201x)" service (listed in Windows Services (Manager)) has sufficient rights. You may try changing it to another Logon. In my case, changing it from "This account" to "Local System account", restarting the "SQL Server (xxxx)" service and SQL Server Management Studio (SSMS), and logging into SSMS again resolved the issue.
Background (in my particular case):
I had 3 different instances of SQL (2008r2, 2012 and 2014) running on my local PC, and was busy moving a folder (which I later discovered contained some SQL data & log database files) to another PC. Halfway through, I stopped the SQL Services in Service (Manager), hoping that the files would move across without issues - since they would now, no longer be in use. I realized that I needed to confirm the database names, and file locations in SQL (in order to set them up again on the new pc), so I copied the SQL data and log files back (to the original locations). After restarting the PC - the majority of the databases on various instances all showed as: "Recovery Pending" in SSMS. After first trying the procedure from stellarinfo (listed as an answer here by #Mahesh Thorat) on 2 of the databases, and still not having any luck, a post SQL SERVER – Where is ERRORLOG? Various Ways to Find ERRORLOG Location on Pinal Dave's SQL Authority website and the post: Operating System error 5(Access is Denied) on SQL Server Central gave me an idea that it could be rights related after looking at the SQL Errorlog and finding "Operating system error 5: "5(Access is denied.)". Another post Msg 3201, Level 16 Cannot open backup device. Operating system error 5(Access is denied.) at SqlBak Blog seems to support this.
I was using azure, the mdf and log file are in different disk and not attached that disk with which it is not able to figure that files and hence the file Recovery Pending
This could happen due to insufficient permissions for a folder with database files (in my case due to a domain migration).
Just give access to the folder for an SQL service's account.
How can I restore (or read in a some decent form) a sybase backup that I've been given to be analyzed?
I have been given a backup from sybase database that contains a single .db and one .log file.
I'm new to sybase and I have no access to original system nor I have any information about the database structure that these files contain.
The thing I know is that backup is probably made with command
dbbackup -c "userid=xxx;password=xxx" -d -t -y D:\path\to\backup
I've been asked to analyze the content of the database and to do that I've set up a SAP ASE 16.0 on RedHat 7.
I have tried to restore the backup using the load database command but all I get is a error report:
Backup Server session id is: 17. Use this value when executing the
'sp_volchanged' system stored procedure after fulfilling any volume change
request from the Backup Server.
Backup Server: 4.10.2.1: Label validation error: first label not VOL1.
Backup Server: 6.31.2.4: Volume rejected.
Backup Server: 1.14.2.2: Unrecoverable I/O or volume error. This DUMP or LOAD
session must exit.
Backup Server: 6.32.2.3: /data/sybase/backup/adbname.db: volume not valid
or not requested (server: , session id: 17.)
Backup Server: 1.14.2.4: Unrecoverable I/O or volume error. This DUMP or LOAD
session must exit.
Msg 8009, Level 16, State 1:
Server 'ASE1', Line 1:
Error encountered by Backup Server. Please refer to Backup Server messages for
details.
the error indicates that the database backup file is not valid.
Are you sure that it is a Sybase ASE dump file. ".db" files look like more DB2 backup files than ASE backup files?
First, you didn't write the restore command for restoring dB and I think you used wrong command for getting backup.
Briefly, for getting backup of a Sybase db you have to write:
create backup
go
Backup files are stored in da\server\instance\dasd\backup\unique_backup_id .
And for load it you have to write:
restore backup "unique_backup_id"
go
If restore backup succeeds, the server automatically shuts down; you must manually restart it.
Resources is: http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36272.1570/html/commands/X16531.htm
We have a very old sybase server. Our database in it is acting up. We need to restore the backup database file from our backup sybase server. But when I try that, I keep getting this error message:
Msg 7205, Level 17, State 2: Line 1: Can't open a connection to site
'SYB_BACKUP'. See the error log file in the SQL Server boot
directory.
That is how I restore the database backup:
1. Use RCP to copy the dump file from the spare server to the primary server. And name the copy "frombkup_mydb.dump".
2. Drop the old database from the primary server, and re-create an empty one.
3. Then use the following command to load the database from the backup dump file:
load database mydb from "/export/home/syb11.dump/frombkup_mydb.dump"
Unfortunately I don't know where the error log file is. I am not familiar with SCO Unix and Sybase.
Does anyone know why the restore doesn't work?
Please help. Thanks.
Jay Chan
It's likely that your Backup Server is not running.
The SAP/Sybase ASE database process requires the backup server to be running for database backups or restores.
To find which database processes are running you can use the showserver command usually located in:
$SYBASE/$SYBASE_ASE/install/showserver
If the backup server is not running (likely), then in the ./install/ directory, look for the file named RUN_SYB_BACKUP
You can start the server by issuing the command (from the ./install/ directory)
startserver -f RUN_SYB_BACKUP
This should start the backup server, and allow you to restore the database.
I have a SQL Server database on my server and I've taken a backup of it. When I try to restore it to a local machine it is throwing me an error and the process is terminating abnormally,
I have created a new empty database in my local machine and trying to restore the .bak into this database with the following code:
RESTORE FILELISTONLY FROM DISK = 'C:\Users\user\Documents\Downloads\LiveDB.bak'
To get LogicalName for both datafile and logfile and I got the error as follows:
Msg 3241, Level 16, State 13, Line 1
The media family on device 'C:\Users\user\Documents\Downloads\LiveDB.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
What is this error causing?
If this is the wrong way to restore a database from a backup file, can someone tell me the step by step procedure to get it working.
Thanks in advance.
This is almost certainly due to the server versions being different. You will get this message if you attempt to restore the database from a newer version of SQL Server to an older version - this is not possible to do. To check the versions, run this command on both servers:
SELECT ##VERSION
Compare the results and make sure the server which you are restoring to is the same version or newer than where the backup was taken.
My mistake was I was restoring from a differential backup instead of a full backup.
I have a stored procedure, which performs a database backup for a specific database.
The problem is, it does work on one server and does not work on another server (the servers are on different machines). The backup drive is a local drive of the server.
On the second server I get the exception "BACKUP DATABASE is terminating abnormally."
In the log file there are the following informations:
... Error: 18204, Severity: 16, State: 1.
... BackupDiskFile::CreateMedia: Backup device 'D:\XXX.bak' failed to create. Operating system error 5(failed to retrieve text for this error. Reason: 15105).
... Error: 3041, Severity: 16, State: 1.
... BACKUP failed to complete the command BACKUP DATABASE XXX. Check the backup application log for detailed messages.
What could be the reason for that and where can I find the mentioned backup application log?
Same problem for me
Solution :
→ Not working
C:\
D:\
... or Any Directory
Code:
BACKUP DATABASE [ERP] TO DISK ='C:\ERP.bak'
BACKUP DATABASE [ERP] TO DISK ='D:\ERP.bak'
BACKUP DATABASE [ERP] TO DISK ='E:\ERP.bak'
Will not work!
→ Working
BUT
Code :
BACKUP DATABASE [ERP] TO DISK ='C:\AtleastOneDir\ERP.bak'
BACKUP DATABASE [ERP] TO DISK ='D:\AtleastOneDir\ERP.bak'
BACKUP DATABASE [ERP] TO DISK ='E:\AtleastOneDir\ERP.bak'
Will work for me!
Sounds like a permission problem.
Do you try to backup to a network drive?
Does the drive D: really exist?
What does the Eventlog tell you? Try the Applicationlog in the Eventlog -> eventvwr.msc
It's just a start...
Try to compile the SP again with "with execute as caller" and run it again.
OK. Encountered the same error in my back up too. The user creating back up had admin privileges on the server too. Make sure that the sub folder exists if not create it manually & run it. For Ex. D:\MsSQL\Backup\MyDB\mydb.bak , make sure that myDB folder exists
This answer covers the same error message, but has nothing to with machine-to-machine access permissions - posted it as a reference in case anyone else ends up here searching for the same error codes.
Ran into the same general error message (Error: 3041, Severity: 16, State: 1.) while testing scheduled automated database backups in SQL Server 2008 . Turns out I was using a feature not available in the standard version of SQL Server 2008 - backup compression. Running the generated T-SQL from my custom database backup maintenance plan task (made available through the "View T-SQL" button) got me more detailed information.
Msg 1844, Level 16, State 1, Line 1
BACKUP DATABASE WITH COMPRESSION is not supported on Standard Edition (64-bit).
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
Changing "Set backup compression" from "Use the default server setting" to "Compress backup" broke the backup script. Changing it back fixed it.
In my case, I restart the SQL Server Service, and now I can make backup like previus.
Try to create windows login on sql server and map it to a windows user that have write permission on the D drive and make sure that the procedure runs under the security context of this user.