So you get prepared to move your SharePoint site to a new server or even upgrade the server that you are currently on that will require either a re-install of SharePoint or reattachment of your content databases. To perform these procedures you have to do first things first and fast. First prepare your content database for move, then move it to its new destination by running these stsadm commands
stsadm -o preparetomove -contentdb <server name: database name> -site <URL name> [-oldcontentdb] <unique identifier>
-Once this command is run successfully detach and reattach all content databases with their web applications again. You will do this by using “deletecontentdb” and “addcontentdb” STSADM commands as shown below:
Delete the Content Databases from the old SharePoint Site
stsadm.exe -o deletecontentdb -url <URL name> -databasename <database name> [-databaseserver] <database server name>
Attach the Content Databases to the new SharePoint Application Server
stsadm.exe -o addcontentdb -url <URL name> -[-assignnewdatabaseid] -[-clearchangelog] -databasename <database name> [-databaseserver database server name>] [-databaseuser <database username>] [-databasepassword <database password>] [-sitewarning <site warning count>] [-sitemax <site max count>]
Once these processes are done you should have a functional SharePoint Site with the contents as they were prior to migration.
Sometime you might end up with Sites and Applications that don’t sync well with the new Content Database this is because the GUID for the ContentDB, Site or WebApp may have changed and you can end-up with an error in your events log similar to the one below
Event Type: Error
Event Source: Office SharePoint Server
Event Category: User Profiles
Event ID: 5553
Time: 11:40:01 PM
failure trying to synch site 980c8184-7ea1-4c28-935c-443395d96ab9 for ContentDB 33e65740-20dd-4523-a1ab-3f57d534da37 WebApp 63cfaa59-6382-4b25-8d15-167c02d271e5. Exception message was Cannot insert duplicate key row in object ‘dbo.UserMemberships’ with unique index ‘CX_UserMemberships_RecordId_MemberGroupId_SID’.
The statement has been terminated..
The are various ways to fix this issue but the one I found most effective was from MisterBeefy he basically uses the SharePoint Inspector to determine the broken Site and the content database that its associated with using the GUID’s in the Event Viewer logs and then uses -PreparetoMove stsadm command using the GUID for the old database then uses the -Sync command which deletes the olddatabases.
Once these processes are done, run a full crawl to Sync your contents.