Triggering incremental backups from an XQL page
After reading around a bit in the latest eXist docs, and finding this, I've written a page called backup.xql; when you hit the page, it will try to create an incremental backup and report success or failure. This is the key function:
declare function local:doBackup() as node()*{ try{ let $params := <parameters> <param name="output" value="export"/> <param name="backup" value="yes"/> <param name="incremental" value="yes"/> </parameters> return system:trigger-system-task("org.exist.storage.ConsistencyCheckTask", $params), <p>Your backup has completed successfully.</p> } catch * ($errorcode , $description , $value ){ <p>Your backup failed with the following error information: {concat($errorcode, '. ', $description, '. ', $value)}</p> } };
The backup location ("output") is relative to WEB-INF/data, and it creates a zip file in there, named for the db, date and time.
After enabling XQuery 3 support in Saxon inside oXygen, I was hoping to see the XQuery above show as valid, but it doesn't; Saxon complains:
catch * ($errorcode , $description , $value ){ (:expected "{", found "(" :) <p>Your backup failed with the following error information: {concat($errorcode, '. ', $description, '. ', $value)}</p> (: Variable $errorcode has not been declared. :)
Still, this stuff is a bit experimental, and it works OK, so I think it's a reasonable strategy to adopt. We should watch the documentation to see if it changes. It's going to replace util:catch, which is deprecated and will be removed for eXist 1.6.