SQL Server Backup failing when using MediaPassword - sql-server

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)

Related

How to recover a dropped table in sql server after a full backup taken

I have to recover a dropped table from a SQL Server database which runs on SQL Server 2016 Standard edition. Database is in full recovery mode.
After the dropped the table, I took a full database backup and then transaction log backup twice. Now can I recover my dropped table with or without using expensive third party tools?
I tried this link and getting error in the last command.
Result of the STOPBEFOREMARK query:
Processed 2104752 pages for database 'databasecopy', file 'databasefilename' on file 1.
Processed 6 pages for database 'datebasecopy', file 'database_log' on file 1.
RESTORE DATABASE successfully processed 2104758 pages in 123.259 seconds (133.405 MB/sec).
Msg 4335, Level 16, State 2, Line 15
The specified STOPAT time is too early. All or part of the database is already rolled forward beyond that point.
Msg 3013, Level 16, State 1, Line 15
RESTORE LOG is terminating abnormally.
RESTORE DATABASE successfully processed 0 pages in 0.544 seconds (0.000 MB/sec).
When I click the Restore option of the original database and click on Timeline option I get the below screen
Table dropped timing from fun_dblog:
Ok, to avoid getting into a long chat about this here is what I suggest:
Restore the full backup you took 4 months ago, NOT the one you took today:
RESTORE DATABASE [databasecopy] FROM DISK = N'OLD_BACKUP.bak' WITH MOVE N'database' TO N'C:\SQLskills\database2.mdf', MOVE N'database_log' TO N'C:\SQLskills\database2_log.ldf', REPLACE, NORECOVERY; GO
Then run the RESTORE up to that LSN:
RESTORE LOG [databasecopy] FROM DISK = N'D:\SQLskills\database_Log2.bak' WITH STOPBEFOREMARK = 'lsn:3420000002597000001', NORECOVERY;
GO
RESTORE DATABASE [databasecopy] WITH RECOVERY; GO
It will not work if you use your current Full Back up because everything in the log at that point has already been committed and you are trying to go back in time. Restore only goes forward in time. That is the reason for your error.

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!

How to catch an error message and send it by EMail?

Now when I take a backup I received error the problem not in error the problem in
How can I catch this body of the error message and send it by EMail or insert it into a table
I have stored for Backup
EXEC dbo.dothebackup2;
After execution I received this error:
Msg 3206, Level 16, State 1, Line 1
Backup device 'Professor_Tape' does not exist. To view existing backup devices, use the sys.backup_devices catalog view. To create a new backup device use either sp_addumpdevice or SQL Server Management Studio.
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
Now how can I save this message in the table?
There are a couple of ways to do this task.
1 - Wrap the call to the backup stored procedure in a SQL Agent job. On failure of the job step, alert a operator, your DBA distribution list to react to the issue.
The Agent automatically keeps history by time or physical file size. See this MSDN article on how to adjust the rentention period.
Check out this MSDN article on how to notify an operator of a job status.
2 - Check out some of the more professional free backup solutions. I use the Ola Hallengren scripts for backups, index maintenance and consistency checks.
I hope this helps you.
Sincerely
John

Resources