SQL Server 2014 restore .bak file - sql-server

I am trying to restore a .bak file (might be created with SQL Server 2010) in SQL Server 2014 with this script
use master;
restore database [Vision] from disk = 'C:\Users\felix_000\Documents\Vision\db\Vision_db.bak'
with replace
and error log is as following:
Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file "C:\SQLData\vision_newschema.mdf" failed with the operating system error 2(The system cannot find the file specified.).
Msg 3156, Level 16, State 3, Line 2
File 'Vision' cannot be restored to 'C:\SQLData\vision_newschema.mdf'. Use WITH MOVE to identify a valid location for the file.
Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file "C:\SQLData\vision_newschema_log.ldf" failed with the operating system error 2(The system cannot find the file specified.).
Msg 3156, Level 16, State 3, Line 2
File 'Vision_log' cannot be restored to 'C:\SQLData\vision_newschema_log.ldf'. Use WITH MOVE to identify a valid location for the file.
Msg 3119, Level 16, State 1, Line 2
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
Msg 3013, Level 16, State 1, Line 2
RESTORE DATABASE is terminating abnormally.
I tried with right click Tasks -> Restore -> Database, it told me that
Restore of database 'Vision' failed. BACKUP LOG cannot be performed because there is no current database backup. (Microsoft.SqlServer.SmoExtended)
Here are the methods I tried,
Run SSMS as administrator
change the file folder security property to FULL CONTROL

Be sure That you are not trying to restaure an Entreprise Edition's Back up on an Express Edition.

Related

Recover Data from .bak File

I could use tips on how to recover a non-standard SQL Server .bak backup file, please.
The background: we have a functioning invoicing program with over 10 years of data from a defunct provider. In past correspondence, the provider told us that the product was built on SQL Server, but never told us what version.
Our goal is to export the data from the program, reformat it, and then load it into another accounting system. The program itself does not have a complete set of export tools so we are hoping to access the data from the .bak files it creates to get all the data for importing into the new system.
I have tried the following SQL Server versions without success:
2000
2005
2008
2008 R2
2012
2014
2016
2017
I have also tried recovering with...
Microsoft SQL Server Management Studio 18 but no backup sets are listed for restoration
SysTools SQL Backup recovery but it returns "Could not identify SQL Server version for the selected .bak file."
SQL Server 2017 on a Linux machine and get the following output...
1> restore database newhouse from disk='/home/me/test.bak'
2> go
Msg 3241, Level 16, State 1, Server 8350, Line 1
The media family on device '/home/me/test.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Server 8350, Line 1
RESTORE DATABASE is terminating abnormally.
1> restore verifyonly from disk='/home/me/test.bak'
2> go
Msg 3241, Level 16, State 1, Server 8350, Line 1
The media family on device '/home/me/test.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Server 8350, Line 1
VERIFY DATABASE is terminating abnormally.
1> restore headeronly from disk='/home/me/test.bak' with nounload
2> go
Msg 3241, Level 16, State 1, Server 8350, Line 1
The media family on device '/home/me/test.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Server 8350, Line 1
RESTORE HEADERONLY is terminating abnormally.
1> restore headeronly from disk='/home/me/test.bak'
2> go
Msg 3241, Level 16, State 1, Server 8350, Line 1
The media family on device '/home/me/test.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Server 8350, Line 1
A .bak file with fictitious data is available here.
Update #1 - in reply #DavidJamesSmith
Here is what I get...
1> restore headeronly
2> from disk = N'/home/me/test.bak'
3> go
Msg 3241, Level 16, State 1, Server 8350, Line 1
The media family on device '/home/me/test.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Server 8350, Line 1
RESTORE HEADERONLY is terminating abnormally.
Update #2 - again in reply #DavidJamesSmith
From what I can tell, the file is not encrypted. I can open the file with gHex - a hex editor in GNOME - and read the data.
As far as the question about the file being corrupted, I do not believe so. I get the same error on any .bak file created by this program whether the .bak file is on the machine that create the .bak or on another machine that I have transferred the file to.
If the file is corrupted, than the program itself is exporting a corrupted version.
Here is what I get on a fresh export running on the machine that has the account software itself.
1> use newhouse
2> restore database newhouserecovery from
3> disk = N'C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\Backup\test.bak'
4> with
5> file = 1,
6> move N'test' to N'C:\Users\me\Backup\test.mdf',
7> move N'test_log' to N'C:\Users\me\Backup\test_log.ldf',
8> nounload,
9> stats = 5
10> go
Changed database context to 'newhouse'.
Msg 3241, Level 16, State 1, Server DESKTO\SQLEXPRESS, Line 2
The media family on device 'C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\Backup\test.bak' is incorrectly formed. SQL Server cannot process this media family.
Msg 3013, Level 16, State 1, Server DESKTO\SQLEXPRESS, Line 2
RESTORE DATABASE is terminating abnormally.
The account software was using Microsoft SQL Server Compact 3.5 Service Pack 2.
Thanks for everyone's help and, especially #lptr for the tip that got me going down the correct track.

Database Mirroring canot be removed error SQL

Ive a database which was mirrored before and now its showing as principal, disconnected/in recovery and we need to restore a back up into it.
Since restore option is disabled,for that purpose I tried to remove the mirroring from MS and whole properties are shows as greyed out disabled.
I tried
alter database mydb set partner off;
which returned
The operating system returned error 21(The device is not ready.) to
SQL Server during a read at offset 0000000000000000 in file 'ldf file
path'. 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 I tried
alter database mydb set offline;
which returned
Msg 1468, Level 16, State 1, Line 1
The operation cannot be performed on database "mydb" because it is involved in a database mirroring session or an availability group.
Some operations are not allowed on a database that is participating in
a database mirroring session or in an availability group.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
Then I tried to restore the DB from the backup file in recovery
RESTORE DATABASE Inetcat_mhra
FROM DISK = '.bak location'
WITH REPLACE,RECOVERY
which returned error
Msg 3104, Level 16, State 1, Line 1 RESTORE cannot operate on database
'mydb' because it is configured for database mirroring or has joined
an availability group. If you intend to restore the database, use
ALTER DATABASE to remove mirroring or to remove the database from its
availability group. Msg 3013, Level 16, State 1, Line 1 RESTORE
DATABASE is terminating abnormally.

I am trying to backup a database and am getting MSG 3013

I have tried to backup in Microsoft SSMS with the GUI backup task, and it fails after a few seconds, so then I tried running this command:
BACKUP DATABASE databasename TO DISK = 'd:\databasename_full.Bak' WITH FORMAT, MEDIANAME = 'd_datbasenamebackup', NAME = 'Full Backup of databasename';
And get a very generic error of the following
Msg 3013, Level 16, State 1, Line 1 BACKUP DATABASE is terminating abnormally.
I am wondering if anyone has come across this error before. Everything I have read is saying there is a media fault, which I know isn't the case.
There is a Microsoft support page for this Error Message 3013.
It is apparently caused when a filemark in your backup device could not be read. Resolution steps below:
To allow SQL Server to perform new backups to the backup device, you
must manually delete or erase the device by using the following
command:
BACKUP DATABASE mydatabase TO DISK='C:\MyDatabase.bak' with FORMAT

Error while restoring db from Enterprise to BI edition of SQL Server

Every day we restore backups from production on 3 different servers. Same process has been used for months and it always works. Recently we decided to start restoring backups from production server on the 4th server meant for BI. We are however unable to do it as database restores well at first and once the restore finishes database goes into "Suspect" mode and the following message is displayed:
Msg 3908, Level 16, State 1, Line 3
Could not run BEGIN TRANSACTION in database 'DatabaseName' because the database is in emergency mode or is damaged and must be restarted.
Msg 3314, Level 16, State 3, Line 3
During undoing of a logged operation in database 'DatabaseName', an error occurred at log record ID (205933:123232:2). Typically, the specific failure is logged previously as an error in the Windows Event Log service. Restore the database or file from a backup, or repair the database.
Msg 3013, Level 16, State 1, Line 3
RESTORE DATABASE is terminating abnormally.
Msg 934, Level 21, State 1, Line 3
SQL Server cannot load database 'DatabaseName' because Change Data Capture is enabled. The currently installed edition of SQL Server does not support Change Data Capture. Either disable Change Data Capture in the database by using a supported edition of SQL Server, or upgrade the instance to one that supports Change Data Capture.
Msg 933, Level 21, State 1, Line 3
Database 'DatabaseName' cannot be started because some of the database functionality is not available in the current edition of SQL Server.
Msg 3314, Level 21, State 5, Line 3
During undoing of a logged operation in database 'DatabaseName', an error occurred at log record ID (205933:123232:1). Typically, the specific failure is logged previously as an error in the Windows Event Log service. Restore the database or file from a backup, or repair the database.
From the error message it looks like we have the problem with one of the log entries, but if this is the case why are we able to restore same backups on different servers?
Our production server from where the backups are coming runs SQL Server 2014 Enterprise edition and has CDC enabled on 4 tables.
Our BI server on which I am trying to restore the backup runs SQL Server BI edition.
Is there any way to bypass this without disabling cdc? Unfortunately we are not allowed to disable this particular feature. I did my reading, but I was unable to find anything helpful.
The only way around that I see is to restore backup on another server, disable cdc and then back up new database and transfer backup to BI server. It more more complicated and hence more likely to break than direct backup transfer. If you see any better way please let me know. Any suggestions will be highly appreciated!

SQL Server Backup failing when using MediaPassword

I have a job that backs up a production database saves it to disk with encryption.
BACKUP DATABASE MyFreshDB
TO DISK='\\HomeServer\data\MyFreshDB.bak'
with copy_only, init,MEDIAPASSWORD='8888'
But I get this error:
Msg 3279, Level 16, State 4, Line 1
Access is denied due to a password failure
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
The script above has been working fine for months, and removing the mediaPassword statement allows the backup to go ahead with no problems.
Any ideas?
The problem was not with the script or password.
The job is scheduled to run every month, but someone ran a backup mid month - without a password, and replaced the backup file with their (unsecured) backup.
This caused the job to fail, as SQL Server (clearly) checks the password of the backup before writing over it. (which is interesting)

Resources