Restore from Unattached Content Databases in SharePoint 2013

Part of your role as a SharePoint administrator is making backups of user content. This means backing up the content databases on a consistent basis. But what happens when you actually need to restore some items from that content database? It doesn’t always make sense to restore an entire content database. You might get the site collection back that was deleted last Tuesday, but you’ll also lose all of the content created and edited in the rest of the sites in the content database.

I’m going to show you how to perform one of the most important restores: the unattached content database restore. It’s the most important because this restore saves the user’s day and doesn’t trample on the other content that’s been added and deleted. You’ll be a hero!

Note: It’s a good idea to practice this backup and restore before you actually need it, as it will help build your confidence and make sure things go smoothly when your practicing and training is put to the test in a real-world scenario.

Setting Up: Create Site Collections

For this exercise, I’m going to create two site collections. One is “important” and has to be restored completely. The second is unimportant and will stay deleted except for one file in a document library.

I create a separate content database and move both site collections onto it, but I only do that because – for this exercise – I don’t want to make a mistake with my real content database and lose data. In a real-world scenario, you can use any content database, and you can be selective about what is getting restored. That’s the whole point of this recovery method.

Stage content onto the sites

I added a document library onto each site, and then added a couple of documents to each library.

2-ImportantFileAddedToUnimportantSite

Set up the new content database

This step isn’t required, but just in case there’s a problem I won’t be deleting my main content database. If you’re doing this as an exercise to test that you understand the process, you might want to do the same.

3-CreateContentDatabase

I moved the two site collections over to the new content database with the Move-SPSite PowerShell command. I reference my “FlashContent” database and I saved it into a variable with the Get-SPContentDatabase command. After doing this, I performed an IISReset /noforce to get everything running smoothly again.

4-MoveSitesToNewContentDB

Backup a content database with SQL Management Studio

For my exercise, I’m using SQL Management Studio to perform the backup and restore of the content database. After starting SQL Management Studio and connecting to the SQL server that holds your SharePoint 2013 content database, right-click your content database and select Tasks, and then select Backup.

5-BackupContentDBFromSQL

Choose the Full backup type and name the backup.

Under Destination, choose Disk. Then click Add to specify the location on which disk that you want to save the backup. If there are additional locations specified, you can select them and click Remove. Click Start Backup to begin.

Restore SQL Database to be an Unattached Content Database

Important:  Remember, this is a simplified example to show you the process. In this example, I’m taking a backup of a database that was just created. The whole point of an unattached content database restore is to not overwrite the entire content database. So it’s really important that you back up your existing content databases before you begin the restore process.

In SQL Management Studio, right-click the Databases folder in the left navigation. Click Tasks and then click Restore database.

There are three pages of options that are displayed for the restore operation: General, Files, and Options.

On the General page, specify the source by selecting Device and then putting in the path to the backup file for the content database.

Once the SQL backup is chosen, the destination database can be selected. Change the database name to something new (just click into the text box and change it) and then select the Files page.

7-SQLRestore-GeneralPage

On the Files page, it’s important that you change the file names to match the new database name you just set. Important: If you don’t change the file names, you’re asking for problems; regardless of the name you set at the General page, the file names will overwrite and so will the database.

Check the box to Relocate the files and then do the same in the Restore As textbox. Next, change the names of the files to match your database name (and the new database name plus “_log” for the log file). Click the Options page, as shown below.

8-SQLRestore-FilesPage

On the Options page, clear the checkbox in the Tail-Log backup section Take tail-log backup before restore. Click OK to begin the restore process.

9-SQLRestoreSuccess

Note: If you don’t clear the tail-log checkbox in the Options page of the restore dialog then the restore operation will try to look back to the original database to look for any missing transactions. Since the database is in use, you will get an error.

10-SQLRestoreFailed-FileInUse

Delete the site collections and the content database. I deleted both the “important” and the “unimportant” site collections, and I also deleted the content database. You can do this easily through Central Administration or through PowerShell.

Once done, I had no sites or content database, and I was ready to restore it through the unattached content database.

Perform the Unattached Content Database

You’ve now got the database back on the SQL server, but SharePoint doesn’t know about it.

In SharePoint Central Administration, select Backup and Restore. Then do the following.

  1. Use Central Administration to restore either the entire content database, a site collection, a site, or a list or library to a backup file.
  2. Use PowerShell to import either the backed up content into an existing or new site.
  3. If you need only a subset of files from a document library, delete the extra files or transfer the documents you need into a library you’re intending to keep.

In my exercise, I’m going to restore:

  •  The “important” site collection – it should have all of the items in the site and should appear just as it used to.
  • The “VERYImportantDocument” from the “unimportant” site collection – I’m only concerned about this file, so I’m not going to restore the entire site. I’ll save the file back into the restored “important” site.

For both of these restores, I’m going to simplify the process and place the restores into an existing content database. I’m not going to create a new content database.

Create a Site Collection from an Unattached Content Database

In Central Administration, click Backup and Restore and then select Recover data from an unattached content database.

At the first screen, specify the database server and the name of the restored and unattached content database. Select your authentication (usually Windows authentication), then select Backup site collection from the Operation to Perform section. Click Next.

11-CA-BackupSiteCollection-1

At the Site collection backup screen, choose which site collection you’re going to backup. Don’t worry that this refers to a backup while we’re in the middle of a recovery process – we’re backing up just the site out of the existing (but unattached) content database to be imported in the next step.

Enter a path to where you want this site collection to be saved. Click Start Backup.

12-CA-BackupSiteCollection-2

We now import the site using a simple PowerShell command:

Restore-SPSite –Identity http://$WebApplication/sites/important -Path “C:\Backup\FlashDB\Important.bak” –ContentDatabase $ContentDB

If the site already exists and you’re trying to copy over it, use the –Force parameter.

The “important” site collection is now restored and functional.

13-Restored-VeryImportantSiteCollection

Import Files from an Unattached Content Database

This is very similar. In this case, at the first screen you’ll choose Export site or list from your list of operations to perform.

At the Export a Web or List screen, choose the Site Collection that contains the file to restore. Select the site in the Site collection that has the list or library, and then select the list.

Check the box to export full security if you want to maintain that information. You can also choose whether or not to backup saved versions of the file or just the most recent. Enter a path to save the list and press Start Export.

14-Restore-SingleList

Use PowerShell to import the list into an existing site:

Import-SPWeb –Identity “http://URLofTheSiteToSaveTheListInto” –Path “C:\PathtoTheBackupFile.cmp

Now you only have to view the site, work with the documents in the restored list, and either delete any unwanted items or move the items you want to keep into a different library.

15-MoveRestoredFile

We’re almost done! Now that your files are restored you’ll want to tidy things up. Delete any leftover document libraries that were part of file level restores and rename any files to avoid conflicts. You may have some sites left over that can be deleted.