-
Notifications
You must be signed in to change notification settings - Fork 1
/
clone_pdbml_noatom.sh
executable file
·123 lines (80 loc) · 2.52 KB
/
clone_pdbml_noatom.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
source ./scripts/env.sh
sync_update=true
if [ ! `which psql` ] ; then
echo "psql: command not found..."
echo "Please install PostgreSQL (https://www.postgresql.org/)."
exit 1
fi
DB_NAME=pdbml_noatom_clone
DB_USER=$USER
echo
echo "Input username of PostgreSQL? (defalut=$USER) "
read db_user
if [ ! -z $db_user ] ; then
DB_USER=$db_user
fi
psql -U $DB_USER -l | grep $DB_NAME > /dev/null || ( echo "database \"$DB_NAME\" does not exist." ; exit 1 )
if [ ! -e $XSD2PGSCHEMA ] ; then
./scripts/update_extlibs.sh
fi
XML_DIR=$PDBML_NOATOM
FILE_EXT_DIGEST=-noatom
XML_SCHEMA=$PDBML_XSD
DB_SCHEMA=$PDBML_SQL
if [ ! -e $DB_SCHEMA ] ; then
java -classpath $XSD2PGSCHEMA xsd2pgschema --xsd $XML_SCHEMA --ddl $DB_SCHEMA --no-rel --doc-key --pg-map-float-decimal --no-key
fi
echo
echo "Do you want to update $DB_NAME? (y [n]) "
read ans
case $ans in
y*|Y*) ;;
*) echo stopped.
exit 1;;
esac
if [ ! -d $PDBML_NOATOM ] ; then
./scripts/update_pdbml.sh
fi
MD5_DIR=chk_sum_psql_pdbml_noatom
relations=`psql -d $DB_NAME -U $DB_USER -c "\d" | wc -l 2> /dev/null`
if [ $sync_update != "true" ] || [ ! -d $MD5_DIR ] || [ $relations -eq 0 ] ; then
sync_update=false
psql -d $DB_NAME -U $DB_USER -f $DB_SCHEMA --quiet
fi
WORK_DIR=pg_work
DATA_DIR=$WORK_DIR/data
ERR_DIR=$WORK_DIR/err
rm -rf $WORK_DIR
mkdir -p $WORK_DIR
if [ $sync_update != "true" ] ; then
mkdir -p $DATA_DIR
fi
mkdir -p $ERR_DIR
err_file=$ERR_DIR/all_err
if [ $sync_update != "true" ] ; then
java -classpath $XSD2PGSCHEMA xml2pgtsv --xsd $XML_SCHEMA --xml $XML_DIR/[0-9a-z]{2} --xml-file-ext gz --work-dir $DATA_DIR --sync $MD5_DIR --no-rel --doc-key --pg-map-float-decimal --no-valid --xml-file-ext-digest $FILE_EXT_DIGEST --db-name $DB_NAME --db-user $DB_USER --max-thrds 8 --skip-range-outlier 2> $err_file
else
java -classpath $XSD2PGSCHEMA xml2pgsql --xsd $XML_SCHEMA --xml $XML_DIR/[0-9a-z]{2} --xml-file-ext gz --sync $MD5_DIR --no-rel --doc-key --pg-map-float-decimal --no-valid --xml-file-ext-digest $FILE_EXT_DIGEST --db-name $DB_NAME --db-user $DB_USER --max-thrds 8 --skip-range-outlier 2> $err_file
fi
if [ $? = 0 ] && [ ! -s $err_file ] ; then
rm -f $err_file
if [ $sync_update != "true" ] ; then
rm -rf $DATA_DIR
fi
else
echo $0 aborted.
exit 1
fi
red='\e[0;31m'
normal='\e[0m'
errs=`ls $ERR_DIR/*_err 2> /dev/null | wc -l 2> /dev/null`
if [ $errs = 0 ] ; then
rm -rf $WORK_DIR
echo "Database ($DB_NAME) is update."
else
echo
echo -e "${red}$errs errors were detected. Please check the log files for more details.${normal}"
exit 1
fi
date