Retain list item IDs between environments using export-spweb/import-spweb

sco gordo 301 Reputation points
2022-04-01T16:17:01.077+00:00

I have a weekly requirement to refresh a list in a lower ONPREM environment with ONPREM production data with consistency in the IDs.
The content is in a Production SPWEB list, and needs to overwrite the equivalent Staging SPWEB list. Can't overwrite the entire contentdb. There is a dependency on the ID's matching in both environments.
I'm using Production export-spweb and Staging import-spweb.

export-spweb -Identity https://intranet.contoso.local/depts/hr/ -ItemUrl "Lists/Employees" -includeversions 2 -path "F:\backup\hr_employees_list.cmp" -CompressionSize 100 -Verbose

Import-SPWeb https://STAGEintranet.contoso.local/depts/hr/ -Path "C:\backup\hr_employees_list.cmp"

When I view the export-spweb log, I can see the ID applied to the list item.
In Staging, I tried deleting the existing ContosoListA items from the list (but leave them in stage1 recycle bin). When I run an import, the item IDs increment: I had 150 items in the Staging list, put them in stage 1 recycle bin, imported the Production list cmp, and the items incremented from 151-300.
I feel like I've done this before but no luck yet. Do I need to permanently remove the Staging list items from Recycle Bin?

Much thanks.

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,221 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,668 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,573 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,798 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Matteo Zamori 86 Reputation points
    2022-04-02T15:35:19.74+00:00

    Hi @sco gordo ,

    you have to permanently delete the list items before attempting to import again from Production using Import-SPWeb.

    Because the list Items ID are already taken (even if they are in the recycle bin, the objects are still present in SP) at the moment of the import command, SP generates new IDs and it results as duplicate items

    0 comments No comments

  2. Emily Du-MSFT 41,786 Reputation points Microsoft Vendor
    2022-04-04T08:22:34.307+00:00

    @sco gordo

    Per my test, even if you delete items from end user recyele bin, when creating new items, the id still starts from 151. It's by default.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. sco gordo 301 Reputation points
    2022-04-05T16:48:48.203+00:00

    Just did another test without first deleting the target content, seems to have worked well. Old item IDs were retained, and new items were added. There was a break in the ID order (ID number 9 was missing in both) which was maintained, the new source items did not 'backfill' the gap. I'm having someone else review it in case I'm missing something.


  4. sadomovalex 3,626 Reputation points
    2022-04-06T15:01:11.087+00:00

    did you try to export list with its content from UI (List settings > Save list as template with "Include content" checked: How to export and import SharePoint list Data with Save list as template) and import it on target? (note that in this case you will probably need to delete whole target site before importing it)

    0 comments No comments