Milan Todorovic
Milan Todorovic

Reputation: 440

exist-db importing files from command line

I have to import a number of xml files into exist-db using command line via shell script. There is a chance that some files already exist and I do not want to overwrite those files. Is there a command line argument (or some other solution) that makes exist skip and report existing file? I have tried browsing official documentation, but I failed to find anything similar.

Upvotes: 1

Views: 463

Answers (1)

Joe Wicentowski
Joe Wicentowski

Reputation: 5294

You're right that eXist's command line client doesn't offer the ability to warn/disable overwrite of resources. (See the client's documentation at http://exist-db.org/exist/apps/doc/java-admin-client.xml#command-line.)

The shortest path to the goal of avoiding overwrite would be to use a WebDAV client that warns when overwriting and gives you options for handling this scenario. For example, I know that Transmit and oXygen XML Editor alert you when a resource/collection exists that would be overwritten. (Behind the scenes, they fetch a list of the resources in a given directory, then warn you when you try to PUT if a resource of this name was in the listing.)

If command line is a must, then you would need some way to list the remote collection or query it for the existence of a resource before proceeding. For example, if you store this query into "check.xq", then you could run it as bin/client.sh -F check.xq:

doc-available("/db/my/collection/file.xml")
(: or for binary docs: 
      util:binary-doc-available("/db/my/collection/file.txt")
   or either XML documents or binary resources: 
      some $resource in xmldb:get-child-resources("/db/my/collection") satisfies $resource eq "file.xml" 
:)

eXist also supports Apache Ant (see http://exist-db.org/exist/apps/doc/ant-tasks.xml). While xdb:store doesn't have a flag controlling overwriting, you could write an ant script that checked for the existence of a file first before storing it with xdb:exist - reporting the existing file and the skip. The nice thing about the ant option is that you can pass your arguments to it as command line parameters, e.g., ant upload-file -Ddir=/path/to -Dfile=file.xml -Dcollection=/db/my/collection - and you can store parameters like the server URL and credentials in a build.properties file. I don't have a full example ready, but if you're interested in pursuing the ant option, give it a try and let me know in comments if you encounter any problems.

Upvotes: 1

Related Questions