Search code examples
powershellsitecoresitecore-media-librarysitecore7.2

Sitecore Powershell Console - Copy Media Items from one DB to another


We are in process of upgrading Sitecore 6.6 to 7.2. Part of upgrade is to migrate all the media items from 6.6 to 7.2.

I tried creating a package but the package size is too large and times out on package installation.

I found link below using Powershell Console where it shows copy-item command: http://blog.najmanowicz.com/2011/11/18/sample-scripts-for-sitecore-powershell-console

I attached the 6.6 to 7.2 version where I can access the 6.6 DB. However copy-item doesn't seem to support different databases.

Could someone please help how I can use SiteCore Powershell or similar to migrate media items from 6.6 to 7.2?


Solution

  • I had a similar issue with a (very large) media library with a similar migration. Packages seems to bomb out around the 2GB mark, instead serialize the items:

    1. Delete everything from /Data/Serialization
    2. Open the media library. Makes sure you have the Developer tab showing (right click somewhere on the toolbar and enable it otherwise)
    3. Select your root media item then Serialize Tree
    4. Wait...
    5. Copy the serialized files from /Data/Serialization to your new server
    6. From the toolbar select Update or Revert Tree depending on your requirements
    7. Profit.

    You can find more info in the Sitecore Serialization Guide and this post by Brian Pedersen

    You should be able to do this in Powershell too (from my understanding). You need to:

    • Add the database to your connectionString.config
    • Add that database to your web.config to <sitecore><databases><database>. You can copy the existing master node and rename the id attribute to match your conneciton name
    • Your legacy database should now be connected to Sitecore interface, you can check it is present in the database selector list from the right of the desktop
    • The powershell command now needs a "from" and "to" location. Assume your database is called "legacy_master", the following should work:

      copy-item "master:\media library\*" "legacy_master:\media library\"