-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdatomic_fixtures_mbrainz_small.sh
More file actions
executable file
·57 lines (44 loc) · 1.81 KB
/
datomic_fixtures_mbrainz_small.sh
File metadata and controls
executable file
·57 lines (44 loc) · 1.81 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
#!/usr/bin/env bash
set -uo pipefail
function fail {
echo "$@"
exit 1
}
function info {
echo "[INFO] $(date +"%T.%3N") $*"
}
function downloadAsNeeded {
curl "$1" -O -C - || fail "Failed to download $1"
}
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
mkdir -p state
pushd state
info "Downloading datomic-pro"
downloadAsNeeded https://datomic-pro-downloads.s3.amazonaws.com/1.0.7469/datomic-pro-1.0.7469.zip
info "Extracting datomic-pro"
if [ ! -d "datomic-pro" ]; then
unzip -q datomic-pro-1.0.7469.zip || fail "Failed to unzip datomic-pro"
mv datomic-pro-1.0.7469 datomic-pro
fi
info "Downloading mbrainz dataset"
mbrainz=https://s3.amazonaws.com/mbrainz/datomic-mbrainz-1968-1973-backup-2017-07-20.tar
mbrainz_backup_dir=datomic-mbrainz-1968-1973-backup-2017-07-20
downloadAsNeeded "$mbrainz"
info "Extracting mbrainz dataset"
if [ ! -d "$mbrainz_backup_dir" ]; then
tar -xf "${mbrainz##*/}" || fail "failed to untar mbrainz dataset"
fi
info "Importing the mbrainz dataset"
# Pick a random port for a short-lived datomic instance
while PORT=$((RANDOM % 60000 + 5000)); lsof -i:$PORT >/dev/null 2>&1; do :; done
sed "s/^port=.*/port=$PORT/" datomic-pro/config/samples/dev-transactor-template.properties > datomic-pro/config/fixtures-transactor.properties
datomic-pro/bin/transactor config/fixtures-transactor.properties &
datomic_transactor_pid=$!
info "Waiting for Datomic to start on port $PORT..."
while ! timeout bash -c "echo > /dev/tcp/localhost/$PORT 2> /dev/null" 2> /dev/null; do :; done
# https://datomic.narkive.com/OUskfRdr/backup-error
datomic-pro/bin/datomic restore-db "file:$(pwd)/mbrainz-1968-1973 datomic:dev://localhost:$PORT/mbrainz-1968-1973"
kill $datomic_transactor_pid
info "Cleaning up $mbrainz_backup_dir"
rm -rf ${mbrainz_backup_dir}
info "Sample dataset ready."