“Database restore failed” – Error when trying to restore a SharePoint database.

Loading

Fixing “Database Restore Failed” in SharePoint – Step-by-Step Guide

Restoring a SharePoint database is crucial for recovering lost data, migrating to a new environment, or setting up a backup. However, the process can sometimes fail due to various reasons, including corrupt backups, permission issues, SQL Server errors, or SharePoint configuration mismatches.

This guide provides a detailed troubleshooting process to fix the “Database Restore Failed” error in SharePoint.


Common Error Messages:

  • “Restore failed due to insufficient permissions.”
  • “The backup file is corrupt or incomplete.”
  • “Cannot overwrite an existing database.”
  • “SQL Server error during restore operation.”
  • “Database is in use and cannot be restored.”

Step 1: Verify Backup File Integrity

The first step is to ensure the backup file is not corrupt or incomplete.

How to Check Backup File Integrity:

  1. Locate the backup file (.bak or .mdf/.ldf files).
  2. Run the following SQL Server command to check for corruption: RESTORE VERIFYONLY FROM DISK = 'C:\Backup\SharePointDB.bak'
  3. If the result is:
    • “The backup set is valid” → Proceed to the next step.
    • “The backup file is corrupt” → Try using a different backup file.

✔ If the backup is valid, move to Step 2.
❌ If the backup is corrupt, use a previous backup or a third-party tool to repair it.


Step 2: Ensure the Database is Not in Use

If the SharePoint database is currently being used, the restore process may fail.

Steps to Take the Database Offline in SQL Server:

  1. Open SQL Server Management Studio (SSMS).
  2. Click Databases → Find the SharePoint database.
  3. Run the following SQL command: ALTER DATABASE SharePointDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  4. Now, retry the restore process.

✔ If successful, proceed to Step 3.
❌ If the error persists, check for permissions or storage issues.


Step 3: Check Disk Space and Storage Availability

If the target server does not have enough space, the restore operation will fail.

How to Check Available Space:

  1. Open File Explorer → Right-click the drive where SQL Server stores databases.
  2. Click Properties → Check available space.
  3. Ensure at least 2x the backup size is available.

Free Up Space (If Needed):

  • Delete unnecessary log files (.ldf).
  • Move old backups to another storage location.
  • Increase disk capacity if required.

✔ If space is available, proceed to Step 4.


Step 4: Restore Database Using SQL Server Management Studio (SSMS)

  1. Open SSMS → Connect to the SQL Server instance.
  2. Right-click Databases → Select Restore Database.
  3. Choose Device → Click Browse → Select your backup file (.bak).
  4. Under Options, check:
    • “Overwrite the existing database” (if needed).
    • “Close existing connections” to avoid conflicts.
  5. Click OK to start the restore process.

✔ If successful, move to Step 7: Reattach the Database to SharePoint.
❌ If the restore fails, proceed to Step 5 for manual restoration.


Step 5: Restore Database Using T-SQL (Manual Method)

If SSMS fails, try using T-SQL commands to restore the database manually.

Run This SQL Command in SSMS:

USE master;
RESTORE DATABASE SharePointDB 
FROM DISK = 'C:\Backup\SharePointDB.bak'
WITH REPLACE,
MOVE 'SharePointDB_Data' TO 'C:\SQLData\SharePointDB.mdf',
MOVE 'SharePointDB_Log' TO 'C:\SQLLogs\SharePointDB.ldf';

✔ If successful, move to Step 7.
❌ If it fails, check for permission issues in Step 6.


Step 6: Fix SQL Server and SharePoint Permissions Issues

Check SQL Server Permissions

  1. Open SSMS → Connect to SQL Server.
  2. Run the following command to ensure your account has the necessary permissions: EXEC sp_addsrvrolemember 'YourAdminAccount', 'sysadmin';
  3. Restart SQL Server and retry the restore.

Check SharePoint Farm Account Permissions

  1. Open SharePoint Central Administration.
  2. Go to Security → Configure Service Accounts.
  3. Ensure the Farm Account has Full Control in SQL Server.

✔ If permissions are correct, retry the restore.


Step 7: Reattach the Restored Database to SharePoint

Once the database is restored, it must be reattached to SharePoint.

Steps to Reattach the Database:

  1. Open SharePoint Management Shell as Administrator.
  2. Run the following PowerShell command: Mount-SPContentDatabase -Name SharePointDB -DatabaseServer SQLSERVERNAME -WebApplication http://YourSharePointSite
  3. Check if the database is now available in SharePoint Central Administration.

✔ If successful, the site should now work correctly.
❌ If there are issues, perform Step 8.


Step 8: Verify and Repair the Restored Database

After restoring, verify that SharePoint services and database connections are intact.

Run SharePoint Health Check:

  1. Open SharePoint Management Shell.
  2. Run the following command to check for issues: Test-SPContentDatabase -Name SharePointDB -WebApplication http://YourSharePointSite
  3. If errors are found, fix them using: Repair-SPContentDatabase -Name SharePointDB

✔ If successful, the database is now restored and operational.


Preventing Future Database Restore Failures

Perform Regular Backups – Always keep multiple backup copies.
Test Backups Before Relying on Them – Run RESTORE VERIFYONLY before restoring.
Use a Staging Environment – Restore to a test server before production.
Monitor Disk Space – Ensure at least 2x backup size is available.
Grant Correct Permissions – Ensure SQL Server and SharePoint accounts have full access.


Leave a Reply

Your email address will not be published. Required fields are marked *