Skip to content

Commit 40266a4

Browse files
committed
Fixed bugs with default charset
1 parent 6cd7eb5 commit 40266a4

File tree

2 files changed

+37
-49
lines changed

2 files changed

+37
-49
lines changed

restore.sh

100755100644
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,17 @@ restore()
113113
fi
114114

115115
if [ -s "$DIR/$BDD/$TABLE.txt" ]; then
116-
117-
if [ ! -z "$(cat $DIR/$BDD/$TABLE.sql | grep -i 'DEFAULT CHARSET=CP1251')" ]; then
118-
charset='cp1251'
119-
else
120-
charset='utf8'
121-
fi
122-
123-
f_log "+ $TABLE, Set default charset: $charset"
116+
117+
f_log "+ $TABLE"
124118

125119
split -l $CONFIG_CHUNK "$DIR/$BDD/$TABLE.txt" "$DIR/$BDD/${TABLE}_part_"
126120
for segment in "$DIR/$BDD/${TABLE}"_part_*; do
127121
f_log "Restore from $segment"
128-
mysql --defaults-extra-file=$CONFIG_FILE $BDD --local-infile -e "SET foreign_key_checks = 0; SET unique_checks = 0; SET sql_log_bin = 0;
129-
SET character_set_database = $charset;
130-
LOAD DATA LOCAL INFILE '$segment'
131-
INTO TABLE $TABLE;
132-
SET foreign_key_checks = 1; SET unique_checks = 1; SET sql_log_bin = 1;"
122+
mysql --defaults-extra-file=$CONFIG_FILE $BDD --local-infile -e "SET foreign_key_checks = 0; SET unique_checks = 0; SET sql_log_bin = 0;
123+
SET character_set_filesystem=utf8;
124+
LOAD DATA LOCAL INFILE '$segment'
125+
INTO TABLE $TABLE;
126+
SET foreign_key_checks = 1; SET unique_checks = 1; SET sql_log_bin = 1;"
133127

134128
if [ -f "$segment" ]; then
135129
f_log "Delete segment $segment"

restore_db.sh

100755100644
Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -68,47 +68,41 @@ restore()
6868
bunzip2 -k $DIR/$TABLE.txt.bz2
6969
fi
7070

71-
if [ -s "$DIR/$TABLE.txt" ]; then
72-
73-
if [ ! -z "$(cat $DIR/$BDD/$TABLE.sql | grep -i 'DEFAULT CHARSET=CP1251')" ]; then
74-
charset='cp1251'
75-
else
76-
charset='utf8'
77-
fi
78-
79-
f_log "+ $TABLE, Set default charset: $charset"
71+
if [ -s "$DIR/$TABLE.txt" ]; then
72+
73+
f_log "+ $TABLE"
8074

81-
split -l $CONFIG_CHUNK "$DIR/$TABLE.txt" "$DIR/${TABLE}_part_"
82-
for segment in "$DIR/${TABLE}"_part_*; do
83-
f_log "Restore from $segment"
84-
time mysql --defaults-extra-file=$CONFIG_FILE $BDD --local-infile -e "SET foreign_key_checks = 0; SET unique_checks = 0; SET sql_log_bin = 0;
85-
SET character_set_database = $charset;
86-
LOAD DATA LOCAL INFILE '$segment'
87-
INTO TABLE $TABLE;
88-
SET foreign_key_checks = 1; SET unique_checks = 1; SET sql_log_bin = 1;"
89-
90-
if [ -f "$segment" ]; then
91-
f_log "Delete segment $segment"
92-
rm "$segment"
93-
fi
94-
done
75+
split -l $CONFIG_CHUNK "$DIR/$TABLE.txt" "$DIR/${TABLE}_part_"
76+
for segment in "$DIR/${TABLE}"_part_*; do
77+
f_log "Restore from $segment"
78+
mysql --defaults-extra-file=$CONFIG_FILE $BDD --local-infile -e "SET foreign_key_checks = 0; SET unique_checks = 0; SET sql_log_bin = 0;
79+
SET character_set_database=utf8;
80+
LOAD DATA LOCAL INFILE '$segment'
81+
INTO TABLE $TABLE;
82+
SET foreign_key_checks = 1; SET unique_checks = 1; SET sql_log_bin = 1;"
9583

96-
if [ ! -f "$DIR/$TABLE.txt.bz2" ]; then
97-
f_log "Delete source file: $TABLE.txt"
98-
rm $DIR/$TABLE.txt
99-
fi
84+
if [ -f "$segment" ]; then
85+
f_log "Delete segment $segment"
86+
rm "$segment"
87+
fi
88+
done
89+
90+
if [ ! -f "$DIR/$TABLE.txt.bz2" ]; then
91+
f_log "Delete source file: $TABLE.txt"
92+
rm $DIR/$TABLE.txt
93+
fi
10094

101-
fi
102-
103-
if [ $DATABASES_TABLE_CHECK ]; then
104-
if [ -f "$DIR/$BDD/$TABLE.ibd" ]; then
105-
if [ ! $(innochecksum $DIR/$TABLE.ibd) ]; then
106-
f_log "$TABLE [OK]"
107-
else
108-
f_log "$TABLE [ERR]"
109-
fi
95+
fi
96+
97+
if [ $DATABASES_TABLE_CHECK ]; then
98+
if [ -f "$DIR/$BDD/$TABLE.ibd" ]; then
99+
if [ ! $(innochecksum $DIR/$TABLE.ibd) ]; then
100+
f_log "$TABLE [OK]"
101+
else
102+
f_log "$TABLE [ERR]"
110103
fi
111104
fi
105+
fi
112106

113107
done
114108

0 commit comments

Comments
 (0)