Skip to content

Instantly share code, notes, and snippets.

@gioele
Last active July 21, 2016 14:00
Show Gist options
  • Save gioele/db5e0fe2cfe58bf0f55af30b065523e6 to your computer and use it in GitHub Desktop.
Save gioele/db5e0fe2cfe58bf0f55af30b065523e6 to your computer and use it in GitHub Desktop.
Backup script for eXist-db
#!/usr/bin/env bash
set -e
set -u
#USER="" # set username
#PASS="" # set password
#HOST="" # set host, eg. localhost:8080
COLLECTION_BASE_URL="http://$USER:$PASS@$HOST/exist/rest/db"
BACKUP_BASE_DIR="./exist-backup-$(date +%Y%m%d-%s)"
echo "Backing up $COLLECTION_BASE_URL to $BACKUP_BASE_DIR"
read -p "Press enter to continue"
function download-subdir () {
local parent_path="$1"
local this_path="$2"
local full_path="$parent_path/$this_path"
local collection_url="$COLLECTION_BASE_URL/$full_path"
local backup_path="$BACKUP_BASE_DIR/$full_path"
local xml_list=/tmp/exist-list.xml
mkdir -p "$backup_path"
curl --silent $collection_url > $xml_list
local files=$(xmlstarlet sel --net -t --value-of '/exist:result/exist:collection/exist:resource/@name' $xml_list || true)
for f in $files ; do
echo "Fetching file $full_path/$f"
curl --silent $collection_url/$f > $backup_path/$f
done
local subdirs=$(xmlstarlet sel --net -t --value-of '/exist:result/exist:collection/exist:collection/@name' $xml_list || true)
for d in $subdirs ; do
echo "Entering directory $full_path/$d"
download-subdir $full_path $d
done
}
download-subdir "" ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment