Get account data xquery

For exporting usergroup information during an eXist-db this xquery fetches all user groups and meta-information for each user. Note that this export will also contain (hashed) passwords for each user.

To run the xquery below on the server:

  • Open a webbrowser, surf to: http://<server>:8877
  • Click on ‘dashboard’.
  • Log in as ‘admin’.
  • Open eXide.
  • Click: ‘New XQuery’ (paste the xquery in the box below to the browserscreen)
  • Click: ‘eval’ to run the xquery.
xquery version "1.0";

declare namespace cfg = "http://exist-db.org/Configuration";

<x>
<users>
{
    for $username in sm:list-users()[not(.=('SYSTEM','admin','guest','xis-webservice'))]
    return (
        <cfg:primary-group user="{$username}" primarygroup="{sm:get-user-primary-group($username)}"/>,
        doc(concat('/db/system/security/exist/accounts/',xmldb:encode-uri($username),'.xml'))/cfg:account
    )
}
</users>
<groups>
{
    for $groupname in sm:list-groups()[not(.=('dba','decor','decor-admin','terminology','issues','editor','tools','debug'))]
    return
        doc(concat('/db/system/security/exist/groups/',xmldb:encode-uri($groupname),'.xml'))/cfg:group
}
</groups>
</x>
  • Save the output as accounts.xml. We will need this later on in the import process.