Saturday, 12 May 2018

Copy bulk Sitecore Items between instances

Today I am going to talk about a very common issue which we face when working with more than one environments/instances of Sitecore.

Moving bulk content and specially media items is a tedious task for which I have written this blog post.
We have some tools that can do the job for us but most of them need paid license to use.
Another way to achieve this is by using a very powerful Sitecore scripting tool called as Sitecore powershell extensions(SPE).

Firstly, we will talk about the tools that can help moving bulk content items:

  1. TDS/Unicorn: These are 2 similar tools, which can be used to serialize items and then sync across various instances of Sitecore. TDS is having more features but needs paid license to use. Unicorn is free and can be used to setup for serializing the items.
  2.  Razl : This is a great tool created by Hedgehoge, which can be used to compare and move items from one instance to other. Using this we can compare 2 databases side by side and simply move items from left to right and vica-versa.

This tool can be very useful as it gives us the clear picture of all items and there presence in each instance.

Now, the other powerful way to achieve the same is using Sitecore powershell.

Migrating Sitecore content using Sitecore powershell

Here, I am taking the scenario of a migration project where we had a requirement to move items from Sitecore 6.6 master DB to Sitecore 8.2 master DB.

For achieving it the following steps were performed:
  • Get the two DB’s into one Sitecore instance. Here “master” is the Sitecore version 8.2 db and “masterold” is the Sitecore version 6.6 master database:
  • To get the 2 database in single instance we have to follow these steps:
    • Add connection strings for the masterold db to Sitecore 8.2 instance connection string:

    • Also, we need to add an additional database node, which we will patch by duplicating the current master database and with the id=”masterold”:

    • Once we have the above settings in place, we can see the two "master" and "masterold" DB in the Sitecore client.
Now, we have the source and the destination available to us at one place so we will write a powershell script to move the content across.
  • First we will download and install powershell on our Sitecore 8.2 instance from here.
  • After installing the powershell package, we will see the new icon for powershell in the start menu:

  • An important point to note: The items that are copied over should have there templates in the destination DB, or copy the templates first.
  • We can see below the content we have to move is inside source folder and we have to move all the subitems in same order from masterold to master DB:

  • Now, switching back to master I have created an empty folder called destination in which we will have all the items from source folder in same order:

  • Now, simply we will open the powershell console and run the following command: 

copy-item -Path “masterold:/sitecore/content/source" -Destination “master:/sitecore/content/destination” -Recurse

  • After running the command we must refresh the parent folder and we will see the items are copied over:

Hope any of the above techniques may help you to move content.
Comments and feedback will be appreciated!!

No comments:

Post a Comment