For Marklogic version below 6.0 on different platforms, XQSync is a tool that can copy documents and their metadata between databases, package documents and their metadata as zip archives, or write them directly to a filesystem. It deals with an entire database, a collection, a directory, or the results of evaluating an XQuery expression. If you're using Marklogic version 6.0 and above, the way to do this is to use a new Marklogic supported tool named mlcp.

Export Marklogic Data

To export data from a source Marklogic, the target Marklogic need need an XDBC server to allow XML Content base Connector (XCC) applications (e.g. XQsync) to communicate with MarkLogic Server. Assuming you the source Marklogic already has one setup, the following command will export data to a .zip file:

[1] In case heap memory size is not enough.[2] Limit export to a subset (directory) of the whole database.[3] Output file name. The actual output file will be /tmp/cq-content-000.zip

Import Marklogic Data

To import data into a target Marklogic, the target Marklogic need need an XDBC server to allow XML Content base Connector (XCC) applications (e.g. XQsync) to communicate with MarkLogic Server. To set one up, use the MarkLogic Server admin interface, which runs on port 8001.

http://<server>:8001Click on Configure > App Servers > Create XDBC, and fill in the following values:

server name: 9000-Docs // 1

root: /tmp // 2

port: 9000

modules: (filesystem)

database: Documents

[1] XDBC server display name. [2] Module directory root.

Once the XDBC server is ready, the following command imported the exported file into the target Marklogic's 'Documents' database:

For debugging purposes, you may tail the Marklogic log to see what's going on as it goes. On my Mac,

cd ~/Library/Application Support/MarkLogic/Data/Logstail -f *

URI privileges are stored in the security database, as are exec privileges, roles, and users. None of these are copied by xqsync. So if the imported documents has roles (e.g. ml-read) not yet exist in the target Marklogic, the log may spit out errors:

It would be possible to use xqsync to export your Security database to fix the above missing user, but importing to Security database would be somewhat tricky. I'd suggest you to first manually create the required missing roles (via Configure > Security > Roles > Create ...) in the target Marklogic and re-import again. On success, the output of the import will look like: