Skip to content

Instantly share code, notes, and snippets.

@ableasdale
Last active December 22, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ableasdale/6508980 to your computer and use it in GitHub Desktop.
Save ableasdale/6508980 to your computer and use it in GitHub Desktop.
Set Forests to Flash Backup Mode
xquery version "1.0-ml";
(:~
: This module allows for the convenient setting of all forests in a given database into a
: specific mode for common management operations. These include:
: <ul>
: <li>Flash backup - Forests can be quiesced so a safe "flash backup" of the filesystem can take place</li>
: <li>All - The "default" for newly created forests; allows both inserts and updates to take place for fragments in
: all forests in that database</li>
: <li>Read only - Places forest in a state where documents can be read from the forest but not updated or removed</li>
: <li>Delete only - Places forest in a state where documents can be removed from the forest but not updated</li>
: </ul>
:)
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $DATABASE as xs:string := "Documents";
(: Public functions :)
declare function local:set-database-forests-to-flash-backup($database-name as xs:string) as empty-sequence() {
local:set-database-forests-to-mode( xdmp:database($database-name), "flash-backup" )
};
declare function local:set-database-forests-to-allow-updates($database-name as xs:string) as empty-sequence() {
local:set-database-forests-to-mode( xdmp:database($database-name), "all" )
};
declare function local:set-database-forests-to-read-only($database-name as xs:string) as empty-sequence() {
local:set-database-forests-to-mode( xdmp:database($database-name), "read-only" )
};
declare function local:set-database-forests-to-delete-only($database-name as xs:string) as empty-sequence() {
local:set-database-forests-to-mode( xdmp:database($database-name), "delete-only" )
};
(: Private functions :)
declare private function local:set-database-forests-to-mode($database-id as xs:unsignedLong, $mode as xs:string) as empty-sequence() {
let $config := admin:get-configuration()
let $_ :=
for $forest-id in admin:database-get-attached-forests($config, $database-id)
return xdmp:set($config, admin:forest-set-updates-allowed($config, $forest-id, $mode))
return admin:save-configuration($config)
};
(: Module main :)
(: Example usage(s) below :)
(: local:set-database-forests-to-flash-backup($DATABASE) :)
(: local:set-database-forests-to-allow-updates($DATABASE) :)
(: local:set-database-forests-to-read-only($DATABASE) :)
(: local:set-database-forests-to-delete-only($DATABASE) :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment