-
Notifications
You must be signed in to change notification settings - Fork 15
/
load-data.sh
56 lines (46 loc) · 1.33 KB
/
load-data.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
#!/bin/bash
FILE="$(pwd)/.env"
if [ -f "$FILE" ]; then
echo Using "$FILE" for environment
source "$FILE"
fi
FILE_ORDER=(
"catchmentsp"
"megadiv_np21"
"nhdflowline_np21"
"nhdplusconnect_np21"
"plusflow_np21"
"plusflowlinevaa_np21"
"characteristic_data.plusflowlinevaa_np21"
"characteristic_data.catchmentsp"
)
declare -A FILES
FILES=(
[catchmentsp]=nhdplus
[megadiv_np21]=nhdplus
[nhdflowline_np21]=nhdplus
[nhdplusconnect_np21]=nhdplus
[plusflow_np21]=nhdplus
[plusflowlinevaa_np21]=nhdplus
[characteristic_data.plusflowlinevaa_np21]=characteristic_data
[characteristic_data.catchmentsp]=characteristic_data
)
problem_files=()
for i in "${FILE_ORDER[@]}"; do
error=false
filename=${i}
namespace=${FILES[$i]}
if [ ! -f "${filename}.pgdump" ]; then
if [ ! -f "${filename}.pgdump.gz" ]; then
aws s3 cp "s3://${NLDI_BUCKET_NAME}/${filename}.pgdump.gz" . || exit 1
fi
gunzip -k -d "${filename}.pgdump.gz" || exit 2
fi
pg_restore "$(pwd)/${filename}.pgdump" -h "${NLDI_DATABASE_ADDRESS}" -p 5432 -a -U postgres --no-password -d nldi -n "${namespace}" --verbose || error=true
if [ $error = true ]; then
problem_files+=("${filename}")
fi
done
echo "Files with errors:"
echo "${problem_files[@]}"
exit 0