MarkLogic 7 - database-backup with rest-api

巧了我就是萌 提交于 2019-12-13 05:55:27

问题


I'm looking to automate backups in ML7 using rest-api. Since that's not available out of the box, I figured that I can just add new extension and setup script with curl command on desired schedule. Sounds easy but for some reason when I try installing my extensions it spits out 'invalid content' and log is showing:

RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: invalid backupdb extension: could not parse XQuery extension backupdb; please see the server error log for detail XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected QName_; backupdb either is not a valid module or does not provide extension functions (delete, get, put, post) in the http://marklogic.com/rest-api/resource/backupdb namespace

Here's the code for my extension:

xquery version "1.0-ml";

module namespace backupdb =
    "http://marklogic.com/rest-api/resource/backupdb";

import module namespace admin = "http://marklogic.com/xdmp/admin"
    at "/MarkLogic/admin.xqy";


declare variable $dbname := "database-backup";
declare variable $s3bucket := "bucket-destination";

declare function backupdb:put(
    $context as map:map,
    $params  as map:map,
    $input   as document-node()*
) as document-node()?
{
  let $dbname := map:get($params, $dbname)
  let $s3bucket := map:get($params, $s3bucket)
  xdmp:database-backup(
    (:xdmp:database-forests(xdmp:database($dbname)), $s3bucket ):)
    xdmp:database-forests(xdmp:database($dbname)), "s3://bucketname/folder" )
        (: "s3://s3bucket/folder"); :)

};

Based on the answer from my other question that I got on stackoverflow I figured that I could use parameter and have curl to something like (after successful installation):

curl --anyauth --user "${USER}":"${pass}" -X PUT -d 'undefined'  'http://localhost:8040/v1/resources/backupdb?rs:database-backup=Documents&rs:bucket-destination=s3://bucket/folder'

POST method returns the same error. What am I doing wrong here?

Any suggestions are welcome.

Thank you, Ernest


回答1:


Also, you have a syntax error in your function (missing a return in the FLWOR) and you do not need to import the Admin library.




回答2:


The curl command above calls the resource service extension. You can't call the extension until you succeed in installing it.

Also,

  • curl requires a PUT or POST request to specify the content-type of the payload with -H 'content-type: _CONTENT_TYPE_HERE_'; when installing, the content-type should be application/xquery
  • pass the local path to the XQuery source file with -d @/path/to/xquerysource.xqy when installing.

Here's the documentation on installing a resource service extension, which includes a curl example:

http://docs.marklogic.com/7.0/REST/PUT/v1/config/resources/%5Bname%5D

Here's the documentation on calling a resource service extension:

http://docs.marklogic.com/7.0/REST/PUT/v1/resources/%5Bname%5D

Hoping that helps,



来源:https://stackoverflow.com/questions/33246818/marklogic-7-database-backup-with-rest-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!