dba/databases  library module
UPR

Summary

Backup operations.
Tags

Author: Christian Grün, BaseX Team 2005-21, BSD License

__source : databases/backups.xqm

Related documents
ViewDescriptionFormat
xqdocxqDoc xml file from the source modulexml
xqparsexqparse xml file from the source modulexml

Imports

This module is imported by 0 modules. It imports 1 modules.

(None)
imports
this
imports

Variables

3.1 $dba:SUB

Summary
Sub category
Type
xs:string

Functions

4.1 dba:action

Arities: dba:action#3UP

Summary
Performs a backup operation.
Signature
dba:action ( $name as xs:string, $info as xs:string, $action as function(*) )  as empty-sequence()
Parameters
  • name as xs:string database
  • info as xs:string info string
  • action as function(*) updating function
Return
  • empty-sequence()redirection
Invoked by 0 functions from 0 modules
    Annotations
    %private()
    %updating()
    Source ( 0 lines)

    4.2 dba:backup-create

    Arities: dba:backup-create#1UR

    Summary
    Creates a database backup.
    Signature
    dba:backup-create ( $name as xs:string )  as empty-sequence()
    Parameters
    • name as xs:string name of database
    Return
    • empty-sequence()redirection
    Invoked by 0 functions from 0 modules
      Annotations
      %updating()
      %rest:GET()
      %rest:path('/dba/backup-create')
      %rest:query-param('name','{$name}')
      Source ( 0 lines)

      4.3 dba:backup-drop

      Arities: dba:backup-drop#2UR

      Summary
      Drops a database backup.
      Signature
      dba:backup-drop ( $name as xs:string, $backups as xs:string* )  as empty-sequence()
      Parameters
      • name as xs:string name of database
      • backups as xs:string* backup files
      Return
      • empty-sequence()redirection
      Invoked by 0 functions from 0 modules
        Annotations
        %updating()
        %rest:GET()
        %rest:path('/dba/backup-drop')
        %rest:query-param('name','{$name}')
        %rest:query-param('backup','{$backups}')
        Source ( 0 lines)

        4.4 dba:backup-restore

        Arities: dba:backup-restore#2UR

        Summary
        Restores a database backup.
        Signature
        dba:backup-restore ( $name as xs:string, $backup as xs:string )  as empty-sequence()
        Parameters
        • name as xs:string database
        • backup as xs:string backup file
        Return
        • empty-sequence()redirection
        Invoked by 0 functions from 0 modules
          Annotations
          %updating()
          %rest:GET()
          %rest:path('/dba/backup-restore')
          %rest:query-param('name','{$name}')
          %rest:query-param('backup','{$backup}')
          Source ( 0 lines)

          Namespaces

          The following namespaces are defined:

          PrefixUri
          annhttp://www.w3.org/2012/xquery
          dbadba/databases 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
          resthttp://exquery.org/ns/restxq
          utildba/util

          6 RestXQ

          Paths defined 3.

          PathMethodFunction
          /dba/backup-createGETdba:backup-create#1
          /dba/backup-dropGETdba:backup-drop#2
          /dba/backup-restoreGETdba:backup-restore#2

          Source Code

          (:~
           : Backup operations.
           :
           : @author Christian Grün, BaseX Team 2005-21, BSD License
           :)
          module namespace dba = 'dba/databases';
          
          import module namespace util = 'dba/util' at '../lib/util.xqm';
          
          (:~ Sub category :)
          declare variable $dba:SUB := 'database';
          
          (:~
           : Creates a database backup.
           : @param  $name  name of database
           : @return redirection
           :)
          declare
            %updating
            %rest:GET
            %rest:path('/dba/backup-create')
            %rest:query-param('name', '{$name}')
          function dba:backup-create(
            $name  as xs:string
          ) as empty-sequence() {
            dba:action($name, 'Backup was created.', function() {
              db:create-backup($name)
            })
          };
          
          (:~
           : Drops a database backup.
           : @param  $name     name of database
           : @param  $backups  backup files
           : @return redirection
           :)
          declare
            %updating
            %rest:GET
            %rest:path('/dba/backup-drop')
            %rest:query-param('name',   '{$name}')
            %rest:query-param('backup', '{$backups}')
          function dba:backup-drop(
            $name     as xs:string,
            $backups  as xs:string*
          ) as empty-sequence() {
            dba:action($name, util:info($backups, 'backup', 'dropped'), function() {
              $backups ! db:drop-backup(.)
            })
          };
          
          (:~
           : Restores a database backup.
           : @param  $name    database
           : @param  $backup  backup file
           : @return redirection
           :)
          declare
            %updating
            %rest:GET
            %rest:path('/dba/backup-restore')
            %rest:query-param('name',   '{$name}')
            %rest:query-param('backup', '{$backup}')
          function dba:backup-restore(
            $name    as xs:string,
            $backup  as xs:string
          ) as empty-sequence() {
            dba:action($name, 'Database was restored.', function() {
              db:restore($backup)
            })
          };
          
          (:~
           : Performs a backup operation.
           : @param  $name    database
           : @param  $info    info string
           : @param  $action  updating function
           : @return redirection
           :)
          declare %private %updating function dba:action(
            $name    as xs:string,
            $info    as xs:string,
            $action  as %updating function(*)
          ) as empty-sequence() {
            try {
              updating $action(),
              util:redirect($dba:SUB, map { 'name': $name, 'info': $info })
            } catch * {
              util:redirect($dba:SUB, map { 'name': $name, 'error': $err:description })
            }
          };