Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r17149]: trunk / eXist / webapp / admin / backup.xqm Maximize Restore History

Download this file

backup.xqm    111 lines (101 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
module namespace backup="http://exist-db.org/xquery/admin-interface/backup";
import module namespace backups="http://exist-db.org/xquery/backups"
at "java:org.exist.backup.xquery.BackupModule";
import module namespace date="http://exist-db.org/xquery/admin-interface/date" at "dates.xqm";
import module namespace system="http://exist-db.org/xquery/system";
declare variable $backup:BACKUP_DIR := "export";
declare function backup:main() as element() {
let $action := lower-case(request:get-parameter("action", "refresh"))
return
<div class="panel">
<h1>Backups</h1>
{
if ($action eq "trigger") then
backup:trigger()
else
()
}
{ backup:display() }
</div>
};
declare function backup:get-directory() {
let $home := system:get-exist-home()
return
if (ends-with($home, "WEB-INF")) then
concat($home, "/data/", $backup:BACKUP_DIR)
else
concat($home, "/webapp/WEB-INF/data/", $backup:BACKUP_DIR)
};
declare function backup:trigger() {
let $incremental := request:get-parameter("inc", ())
let $zip := request:get-parameter("zip", ())
let $params :=
<parameters>
<param name="output" value="{$backup:BACKUP_DIR}"/>
<param name="backup" value="yes"/>
<param name="incremental" value="{if ($incremental) then 'yes' else 'no'}"/>
<param name="zip" value="{if ($zip) then 'yes' else 'no'}"/>
</parameters>
return (
system:trigger-system-task("org.exist.storage.ConsistencyCheckTask", $params),
<div class="process">
A backup has been triggered on the server. It will be processed once all running
transactions have returned.
</div>
)
};
declare function backup:display() {
let $backupDir := backup:get-directory()
return
<form action="{session:encode-url(request:get-uri())}" method="GET">
<div class="inner-panel">
<h2>Available DB Backups</h2>
{ backup:list-backups($backupDir) }
<button class="refresh" type="submit" name="action" value="refresh">Refresh</button>
</div>
<div class="inner-panel">
<h2>Trigger Backup</h2>
<input type="checkbox" name="zip"/> Zip (Don't use for database with more than 4gb)<br/>
<input type="checkbox" name="inc"/> Incremental<br/>
<div class="spacing">
<button type="submit" name="action" value="trigger">Trigger</button>
</div>
<input type="hidden" name="panel" value="backup"/>
</div>
</form>
};
declare function backup:list-backups($dir as xs:string) as element(table) {
<table class="browse backups" cellspacing="0">
<tr>
<th>Name</th>
<th>Created</th>
<th>Incremental</th>
</tr>
{
let $backups := backups:list($dir)/exist:backup
return
if (count($backups) eq 0) then
<tr>
<td colspan="4">No backup archives found.</td>
</tr>
else
for $backup in $backups
let $date := xs:dateTime($backup/exist:date)
let $download := concat(session:encode-url(xs:anyURI("backups/")), $backup/@file/string())
order by $date descending
return
<tr>
<td>
{
if (ends-with($backup/@file, ".zip")) then
<a href="{$download}">{$backup/@file/string()}</a>
else
$backup/@file/string()
}
</td>
<td>{date:format-dateTime($date)}</td>
<td class="last">{$backup/exist:incremental/text()}</td>
</tr>
}
</table>
};