Search code examples
powershellsharepointsharepoint-2010

Failing to export web from SharePoint


I'm attempting to export sites from SharePoint 2010, out of the root site collection via powershell and every Export-SPWeb command fails with this message.

Export-SPWeb : String or binary data would be truncated.
The statement has been terminated.

It happens for any web in any site collection I've tested as well, not just the web application root.

From what I understand, this is an error indicating that URLs are over 260 characters long. However, this happens even if there are no files in the site. In case it's relevant, the FQDN of the address is 28 characters.

Here is an actual example I tried (with different host name of course).

> new-spweb http://sharepoint.example.com/a

Url
---
http://sharepoint.example.com/a

> export-spweb http://sharepoint.example.com/a -path "a.cmp"
Export-SPWeb : String or binary data would be truncated.
The statement has been terminated.
At line:1 char:13
+ export-spweb <<<<  http://sharepoint.example.com/a -path "a.cmp"
    + CategoryInfo          : InvalidData: (Microsoft.Share...CmdletExportWeb:SPCmdletExportWeb) [Export-SPWeb], SqlException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletExportWeb

Does anyone know of a reason that this would happen, and possibly how to fix it since the error message seems to be incorrect?


Solution

  • It appears the way to resolve this in our case was to backup and restore the site collections to newly created site collections. In our goal, we are splitting a large site collection to multiple site collections using Export-SPWeb and then Import-SPWeb later on to new homes.

    Effectively this is what we did in case it helps anyone else with the same mysterious issue.

    First make sure the new URL for the backup of the main site collection doesn't cause them to be over the 260 character limit. If they are over 260 characters, you can still do Backup-SPSite but it will fail to restore with Restore-SPSite.

    Made some minor modification to the example found on Microsoft forums. Here the new site collection would be sites/NewSC.

    declare @oldSiteCollection nvarchar(20) = N'sites/old'
    declare @newSiteCollection nvarchar(20) = N'sites/NewSC'
    
    SELECT
       concat([DirName], N'/', [LeafName]) AS [FullRelativePath],
       len(concat(@newSiteCollection, [DirName], N'/', [LeafName])) - len(@oldSiteCollection) AS [Length]
    FROM 
       [dbo].[AllDocs]
    where
        [DirName] not like 'sites/%'
        and len(concat(@newSiteCollection, [DirName], N'/', [LeafName])) - len(@oldSiteCollection) > 260
    ORDER BY 
       [FullRelativePath] desc
    

    This query will give a list of things to deal with before the following commands will be successful. You want no results to be returned from the query before backup / restore.

    Next a Backup-SPSite on the main site collection

    Backup-SPSite http://sharepoint.example.com/sites/old -Path e:\old.bak
    

    Afterward a Restore-SPSite to the new location

    Restore-SPSite http://sharepoint.example.com/sites/NewSC -Path e:\old.bak
    

    After this whole maneuver, Export-SPWeb works as expected.

    If I had to guess on why this issue is happening, it may be because we have been using the same content databases since SharePoint 2003. Upgrading over the years from 2003 to 2007 to 2010 has possibly taken a toll on these.

    With that in mind, using Move-SPSite to a new content database didn't resolve this either. The only thing that has worked after weeks of various attempts is the above method.