Search code examples
marklogic

Marklogic How to save multiple Workspaces


I have multiple Workspaces in Marklogic Qconsole. How can I export all workspaces at once. Instead of export one workspace at a time to computer. Thanks


Solution

  • Your workspaces are saved in the App-Services database. They have a qconsole:workspace element, and will have a qconsole:userid element with your userid.

    Using some of the built-in functions that are used to generate the export by the QConsole application, you can transform the workspace into the export format.

    Below is a query that you can run to find all of your workspaces, generate the export format, and then save them to the /tmp directory on the server:

    xquery version "1.0-ml";
    declare namespace qconsole="http://marklogic.com/appservices/qconsole";
    import module namespace qconsole-model="http://marklogic.com/appservices/qconsole/model" 
      at "/MarkLogic/appservices/qconsole/qconsole-model.xqy";
    import module namespace amped-qconsole = "http://marklogic.com/appservices/qconsole/util-amped" 
      at "/MarkLogic/appservices/qconsole/qconsole-amped.xqy";
    
    xdmp:invoke-function(
      function(){
        let $workspaces := cts:search(/qconsole:workspace, 
                             cts:element-value-query(xs:QName("qconsole:userid"), 
                               string(xdmp:get-current-userid())))
        for $workspace in $workspaces
        let $name := $workspace/qconsole:name/string()
        let $wsid := $workspace/qconsole:id/data()
        let $export := qconsole-model:export-workspace($wsid)
        return 
          xdmp:save("/tmp/"||$name||".xml", $export)
      },
      <options xmlns="xdmp:eval">
        <database>{xdmp:database("App-Services")}</database>
      </options>
    )