Sql-server – How to repair backup of .mdf file database

sql server

One of our clients gets the following error when trying to backup a database:

System.Data.SqlClient.SqlException: SQL Server detected a logical
consistency-based I/O error: incorrect checksum (expected:
0x121db60d; actual: 0x521db60d). It occurred during a read of page
(1:1632) in database ID 4 at offset 0x00000000cc0000 in file
'C:\Program Files (x86)\Microsoft SQL
Server\MSSQL.1\MSSQL\DATA\MSDBData.mdf'. Additional messages in the
SQL Server error log or system event log may provide more detail.
This is a severe 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. Could not insert a
backup or restore history/detail record in the msdb database. This
may indicate a problem with the msdb database. The backup/restore
operation was still successful.

I tried to perform checkdb, checkdb repair_rebuild as well as checkdb REPAIR_ALLOW_DATA_LOSS but none of these corrected the issues is the MSDB database.

My question is: can I just grab a clean MSDB database from another instance to recover corrupt one or do I really have to uninstall/reinstall SQL Server?

Best Answer

You're getting this while trying to backup any database?

msdb is used for a bunch of things and you'll want to make sure it's okay. But critically, it sounds like your corruption is in a table which is used for backups, and this is a good thing, because you don't necessarily need that data.

Start by scripting out all your SQL Agent jobs, exporting all your SSIS packages that you've put in msdb, and anything else you can think of that uses msdb.

Now do some investigation to find out what that corrupt page is used for....

...but ultimately, your best bet is likely to be to stop the instance for a moment, pull out the msdb MDF and LDF files (so you have copies), restore from a backup from a different database (and check again for corruption), and then redeploy all your maintenance jobs, agent jobs, SSIS packages, and anything else you can think of.

You might be able to swap your MDF and LDF files onto another machine and extract extra information that you may have missed, but this should at least get you going again.