-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
createdb.sh
executable file
·107 lines (93 loc) · 2.74 KB
/
createdb.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
set -e -o pipefail -u
BASE_DOWNLOAD_URL="${MUSICBRAINZ_BASE_FTP_URL:-$MUSICBRAINZ_BASE_DOWNLOAD_URL}"
IMPORT="fullexport"
FETCH_DUMPS=""
WGET_OPTIONS=""
HELP=$(cat <<EOH
Usage: $0 [-wget-opts <options list>] [-sample] [-fetch] [MUSICBRAINZ_BASE_DOWNLOAD_URL]
Options:
-fetch Fetch latest dump from MusicBrainz download server
-sample Load sample data instead of full data
-wget-opts Pass additional space-separated options list (should be
a single argument, escape spaces if necessary) to wget
Default MusicBrainz base download URL: $BASE_DOWNLOAD_URL
EOH
)
if [ $# -gt 4 ]; then
echo "$0: too many arguments"
echo "$HELP"
exit 1
fi
while [ $# -gt 0 ]; do
case "$1" in
-wget-opts )
shift
WGET_OPTIONS=$1
;;
-sample )
IMPORT="sample"
;;
-fetch )
FETCH_DUMPS="$1"
;;
-* )
echo "$0: unrecognized option '$1'"
echo "$HELP"
exit 1
;;
* )
BASE_DOWNLOAD_URL="$1"
;;
esac
shift
done
TMP_DIR=/media/dbdump/tmp
case "$IMPORT" in
fullexport )
if [[ $MUSICBRAINZ_STANDALONE_SERVER -eq 1 ]]; then
echo "$0: Only sample data can be loaded in standalone mode"
echo "$HELP"
exit 1
fi
DUMP_FILES=(
mbdump.tar.bz2
mbdump-cdstubs.tar.bz2
mbdump-cover-art-archive.tar.bz2
mbdump-derived.tar.bz2
mbdump-stats.tar.bz2
mbdump-wikidocs.tar.bz2
);;
sample )
if [[ $MUSICBRAINZ_STANDALONE_SERVER -eq 0 ]]; then
echo "$0: Only full data can be loaded in mirror mode"
echo "$HELP"
exit 1
fi
DUMP_FILES=(
mbdump-sample.tar.xz
);;
esac
if [[ $FETCH_DUMPS == "-fetch" ]]; then
FETCH_OPTIONS=("${IMPORT/fullexport/replica}" --base-download-url "$BASE_DOWNLOAD_URL")
if [[ -n "$WGET_OPTIONS" ]]; then
FETCH_OPTIONS+=(--wget-options "$WGET_OPTIONS")
fi
fetch-dump.sh "${FETCH_OPTIONS[@]}"
fi
for F in "${DUMP_FILES[@]}"; do
if ! [[ -a "/media/dbdump/$F" ]]; then
echo "$0: The dump '$F' is missing"
exit 1
fi
done
echo "found existing dumps"
dockerize -wait "tcp://${MUSICBRAINZ_POSTGRES_SERVER}:5432" -timeout 60s sleep 0
mkdir -p $TMP_DIR
cd /media/dbdump
INITDB_OPTIONS='--echo --import'
if ! carton exec -- /musicbrainz-server/script/database_exists MAINTENANCE; then
INITDB_OPTIONS="--createdb $INITDB_OPTIONS"
fi
# shellcheck disable=SC2086
carton exec -- /musicbrainz-server/admin/InitDb.pl $INITDB_OPTIONS -- --skip-editor --tmp-dir $TMP_DIR "${DUMP_FILES[@]}"