【问题标题】:Xquery. How to check current incremental backup status?查询。如何查看当前的增量备份状态?
【发布时间】:2019-03-25 13:03:57
【问题描述】:

我已经编写了一个 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 为 false,因此它转到最后一行,即 else 条件。这不会为增量备份返回任何内容。 completedin-progress 都不是。我想知道 markLogic 是如何获取时间戳的。请在这方面提供帮助。

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

【问题讨论】:

    标签: xquery marklogic marklogic-8 marklogic-9


    【解决方案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)
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-05
      • 2011-01-02
      • 1970-01-01
      • 2012-03-20
      • 2020-10-09
      • 1970-01-01
      • 2021-12-17
      相关资源
      最近更新 更多