我编写了一个Xquery,它在增量备份进行时执行。我知道备份状态返回三个可能的值- completed、in-progress和failed。不确定最后一个的确切值,但无论如何,这是我的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条件。这不会为增量备份返回任何内容。既不是completed也不是in-progress。我想知道markLogic是如何获得时间戳的。请协助处理这个问题。
可以从零开始提供您自己的xquery。我可以更新我的。
我甚至提取了Job并在函数xdmp:database-backup-status(())的输出中进行搜索,但是结果集中也不存在这个作业id。
发布于 2019-03-26 00:51:56
MarkLogic提供了管理模块来提供您试图通过其他方法获得的大部分信息。Admin模块(通常可以在/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)这只是一些示例代码片段,不是可执行的,但它会让您朝着正确的方向前进。
https://stackoverflow.com/questions/55338449
复制相似问题