-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathrefresh-data.sh
More file actions
executable file
·74 lines (59 loc) · 1.48 KB
/
refresh-data.sh
File metadata and controls
executable file
·74 lines (59 loc) · 1.48 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# ==========================================================================
# Import data from a gzipped dump. Provide the filename as the first arg.
# NOTE: Run this script while in the project root directory.
# It will not run correctly when run from another directory.
# ==========================================================================
set -e
usage() {
cat << EOF
Please download a recent database dump before running this script:
./refresh-data.sh prodpub_main_django.sql.gz
Additional options:
--noindex Do not update search indexes after refreshing
EOF
exit 1;
}
check_data() {
echo 'Validating local dump file'
gunzip -t "$refresh_dump_name"
}
refresh_data() {
echo 'Importing refresh db'
gunzip < "$refresh_dump_name" | cfgov/manage.py dbshell > /dev/null
}
initial_data() {
./initial-data.sh
}
update_index() {
source ./index.sh
}
get_data() {
if [[ -z "$refresh_dump_name" ]]; then
refresh_dump_name='prodpub_main_django.sql.gz'
else
if [[ $refresh_dump_name != *.sql.gz ]]; then
echo "Input dump '$refresh_dump_name' expected to end with .sql.gz."
exit 2
fi
fi
}
noindex=false
for arg in "$@"; do
shift
case "$arg" in
"--noindex")
noindex=1
;;
*)
refresh_dump_name=$arg
;;
esac
done
get_data
check_data
refresh_data
initial_data
if [[ $noindex -ne 1 ]]; then
update_index
fi