Error using Move-SPSite cmdlet


This post discusses the following error:

Move-SPSite : Cannot insert duplicate key row in object ‘dbo.AllSites’ with unique index ‘Sites_Id’. The duplicate key value is <GUID>.

Let’s say you have 1 Web Application with 2 content databases:
– Database 1
– Database 2

Database 1 contains a site collection with the following URL: http://portal.contoso.com.
For some reason, you moved the site collection using the following cmdlet:

Move-SPSite http://portal.contoso.com -DestinationDatabase "Database 2" -Confirm:$false

image

So far so good. Now let’s say you want to move this site collection back to Database 1.
You would run:

Move-SPSite http://portal.contoso.com -DestinationDatabase "Database 1" -Confirm:$false

This produces the following error:

image

Solution
This is happening because the site collection has not been completely deleted from the content database.
When you run Move-SPSite, the site collection gets moved to the new content database.
However, the site collection in the source Content Database was not completely removed. The site collection "Deleted" flag was set to 1.

This means it is scheduled for deletion. The Gradual site delete timer jobs will delete the site collection from the content database. By default, this timer job runs once a day. To ensure the site is completely deleted, run the timer job. As this timer job runs for each Web Application, make sure you select the correct Web Application

image

After you ran the Gradual Site Delete timer job, you will be able to move the site collection back to Database 1.

Advertisements

One thought on “Error using Move-SPSite cmdlet

  1. You are the man!!! I was facing this same problem using the object model. Specifically SPContentDatabase.Move(). Now I just need to run this timer job programatically and it should work. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s