MOSS MVP

I've moved my blog to http://blog.falchionconsulting.com!. Please update your links. This blog is no longer in use--you can find all posts and comments at my new blog; I will no longer be posting to this site and comments have been disabled.

Sunday, May 18, 2008

Exporting and Importing List Folders

Those familiar with my commands know that I've got a few commands that I created to handle the exporting and importing of list items and lists using the content deployment API.  If you're familiar with the API then you know that there's also an option to export and import list folders.  Until a few weeks ago I didn't have a need for this so I hadn't bothered leveraging it but then I got a project which required migrating content from one farm to another, one folder at a time.  Fortunately I already had my other commands as a starting place so it only took me about an hour to build out two new commands: gl-exportlistfolder and gl-importlistfolder.  Note that I built and published the commands several weeks ago - I'm just way behind in getting them (and others) documented.

The commands are more or less identical to the gl-exportlist and gl-importlist commands which I used as a starting place.  The syntax and examples of the two commands are shown below starting with the export command:

C:\>stsadm -help gl-exportlistfolder

stsadm -o gl-exportlistfolder

Exports a list.

Parameters:
        -url <folder url>
        -filename <export file name>
        [-overwrite]
        [-includeusersecurity]
        [-haltonwarning]
        [-haltonfatalerror]
        [-nologfile]
        [-versions <1-4>
                1 - Last major version for files and list items
                2 - The current version, either the last major or the last minor
                3 - Last major and last minor version for files and list items
                4 - All versions for files and list items (default)]
        [-cabsize <integer from 1-1024 megabytes> (default: 25)]
        [-nofilecompression]
        [-includedescendants <All | Content | None>]
        [-quiet]

To export the root folder and no sub-folders (effectively giving you all items in the root folder without any sub-folders) you would run the following:

stsadm -o gl-exportlistfolder -url http://portal/documents -filename c:\exportdata\docs -nofilecompression -includedescendants none

To export a sub-folder and all of its child sub-folders you would run something similar to the following:

stsadm -o gl-exportlistfolder -url http://portal/documents/subfolder1 -filename c:\exportdata\docs -nofilecompression

And of course an export wouldn't be much good without an import:

C:\>stsadm -help gl-importlistfolder

stsadm -o gl-importlistfolder

Imports a list item or items.

Parameters:
        -url <url of list folder to import to>
        -filename <import file name>
        [-includeusersecurity]
        [-haltonwarning]
        [-haltonfatalerror]
        [-nologfile]
        [-updateversions <1-3>
                1 - Add new versions to the current file (default)
                2 - Overwrite the file and all its versions (delete then insert)
                3 - Ignore the file if it exists on the destination]
        [-nofilecompression]
        [-quiet]
        [-retargetlinks (resets links pointing to the source to now point to the target)]
        [-sourceurl <url to original source folder> (use if retargetlinks)]
        [-retainobjectidentity]

To import the documents that have been exported above you would run something like the following (note that the folder URL could be the URL of a sub-folder):

stsadm -o gl-importlistfolder -url http://portal/documents -filename c:\exportdata\docs -nofilecompression

1 comment:

Chas said...

When I try this the import does indeed replicate the folder structure exported, but creates a top level folder above it. In your example this folder would be called Documents. Any Ideas?