Xquery。如何查看当前增量备份状态?

时间:2019-03-25 13:03:57

标签: xquery marklogic marklogic-8 marklogic-9

我已经编写了一个Xquery,该Xquery在进行增量备份时执行。我知道备份状态会返回三个可能的值- completedin-progressfailed。不确定最后一个的确切值,但是无论如何这是我的xquery-

    xquery version "1.0-ml";

declare function local:escape-for-regex
  ( $arg as xs:string? )  as xs:string {

   replace($arg,
           '(\.|\[|\]|\\|\||\-|\^|\$|\?|\*|\+|\{|\}|\(|\))','\\$1')
 } ;

declare function local:substring-before-last
  ( $arg as xs:string? ,
    $delim as xs:string )  as xs:string {

   if (matches($arg, local:escape-for-regex($delim)))
   then replace($arg,
            concat('^(.*)', local:escape-for-regex($delim),'.*'),
            '$1')
   else ''
 } ;

let $server-info := doc("/config/server-info.xml")
let $content-database :="xyzzy"
let $backup-directory:=$server-info/configuration/server-info/backup-directory/text()
let $backup-latest-dateTime := xdmp:filesystem-directory(fn:concat( $backup-directory,'/',$content-database))/dir:entry[1]/dir:filename/text()
let $backup-latest-date := fn:substring-before($backup-latest-dateTime,"-")
let $backup-info := cts:search(/,cts:element-value-query(xs:QName("directory-name"),$backup-latest-date))
let $new-backup := if($backup-info)
                    then fn:false()
                   else fn:true()
let $db-bkp-status := if($new-backup)
                        then (xdmp:database-backup-status(())[./*:forest/*:backup-path[fn:contains(., $backup-latest-dateTime)]][./*:forest/*:incremental-backup eq "false"]/*:status)
                      else (xdmp:database-backup-status(())[./*:forest/*:backup-path[fn:contains(., $backup-latest-dateTime)]][./*:forest/*:incremental-backup eq "true"][./*:forest/*:incremental-backup-path[fn:contains(., fn:replace(local:substring-before-last(xs:string(fn:current-date()), "-"), "-", ""))]]/*:status)

return $db-bkp-status

我们维护一个存储备份状态的配置文件。如果有新的完整备份日,则$backup-info将不返回任何内容。如果是每日增量备份,则它将返回配置。我用它只是为了检查今天的备份是新的完整备份还是增量备份。对于增量日期$backup-info为假,因此它转到最后一行,即else条件。这不会为增量备份返回任何内容。 completedin-progress都没有。我不知道markLogic如何获取时间戳。请协助。

随时从头开始提供您自己的xquery。我可以更新我的。
我什至拿出Job ID并在函数xdmp:database-backup-status(())的输出中进行搜索,但结果集中也不存在该Job ID。

1 个答案:

答案 0 :(得分:1)

MarkLogic provides the Admin modules,以提供您尝试通过其他方法获取的许多信息。 Admin UI模块(通常在/ opt / MarkLogic / Modules / MarkLogic / Admin / Lib中找到)包含许多有用的代码,可以将其修改为获取这些详细信息。在这种情况下,我将参考database-status-form.xqy

define function db-mount-state(
  $fstats as node()*,
  $fcounts as node()*,
  $dbid as xs:unsignedLong)
{
let $times := $fstats/fs:last-state-change,
  $ls := max($times),
  $since :=
    if (not(empty($ls)))
    then concat(" since ", longDate($ls), " ", longTimeSecs($ls))
    else ""
return concat(database-status($dbid,$fstats,$fcounts),$since)
}

define function backup-recov-state($fstats as node()*)
{
  if(empty($fstats/fs:backups/fs:backup)
       and
     empty($fstats/fs:restore))
  then
    "No backup or restore in progress"
  else
    if(empty($fstats/fs:backups/fs:backup))
    then
      "Restore in progress (see below for details)"     
    else
      "Backup in progress (see below for details)"
}

...针对您的数据库调用函数,然后从所需的元素中提取详细信息:

let $last-full-backup := max($fstats/fs:last-backup)
let $last-incremental-backup : = max($fstats/fs:last-incr-backup
return ($last-full-backup, $last-incremental-backup)

这只是一些示例代码片段,不是可执行的,但它应该使您朝着正确的方向前进。