=fix load data from source file with charset cp1251
This commit is contained in:
parent
e2efabe8e4
commit
c635e3bc29
|
@ -188,6 +188,8 @@ Examples:
|
|||
backup.sh --verbose --dir="/var/backups/mysql" --config="/etc/mysql/debian.cnf" --exclude="mysql" --lifetime="1 day ago"
|
||||
backup.sh --verbose --dir="/home/backups/mysql" --exclude="mysql" --lifetime="1 day ago"
|
||||
backup.sh --verbose --dir="/home/backups/mysql" --exclude="mysql" --exclude-tables="tbl_template" --lifetime="1 day ago"
|
||||
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
|
|
|
@ -185,6 +185,8 @@ Examples:
|
|||
backup.sh --verbose --dir="/var/backups/mysql" --config="/etc/mysql/debian.cnf" --lifetime="1 day ago"
|
||||
backup.sh --verbose --dir="/home/backups/mysql" --lifetime="1 day ago"
|
||||
backup.sh --verbose --dir="/home/backups/mysql" --exclude-tables="tbl_template" --lifetime="1 day ago"
|
||||
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
|
|
23
restore.sh
23
restore.sh
|
@ -113,13 +113,20 @@ restore()
|
|||
fi
|
||||
|
||||
if [ -s "$DIR/$BDD/$TABLE.txt" ]; then
|
||||
|
||||
if [ ! -z "$(cat $DIR/$BDD/$TABLE.sql | grep -i 'DEFAULT CHARSET=CP1251')" ]; then
|
||||
charset='cp1251'
|
||||
else
|
||||
charset='utf8'
|
||||
fi
|
||||
|
||||
f_log "+ $TABLE"
|
||||
f_log "+ $TABLE, Set default charset: $charset"
|
||||
|
||||
split -l $CONFIG_CHUNK "$DIR/$BDD/$TABLE.txt" "$DIR/$BDD/${TABLE}_part_"
|
||||
for segment in "$DIR/$BDD/${TABLE}"_part_*; do
|
||||
f_log "Restore from $segment"
|
||||
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;
|
||||
mysql --defaults-extra-file=$CONFIG_FILE $BDD --local-infile -e "SET foreign_key_checks = 0; SET unique_checks = 0; SET sql_log_bin = 0;
|
||||
SET character_set_database = $charset;
|
||||
LOAD DATA LOCAL INFILE '$segment'
|
||||
INTO TABLE $TABLE;
|
||||
SET foreign_key_checks = 1; SET unique_checks = 1; SET sql_log_bin = 1;"
|
||||
|
@ -130,13 +137,13 @@ restore()
|
|||
fi
|
||||
done
|
||||
|
||||
if [ -f "$DIR/$BDD/$TABLE.txt.bz2" ]; then
|
||||
f_log "Delete source: $TABLE.txt"
|
||||
rm $DIR/$BDD/$TABLE.txt
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [ -f "$DIR/$BDD/$TABLE.txt" ]; then
|
||||
f_log "Delete source: $TABLE.txt"
|
||||
rm $DIR/$BDD/$TABLE.txt
|
||||
fi
|
||||
|
||||
if [ $DATABASES_TABLE_CHECK ]; then
|
||||
if [ -f "$DIR/$BDD/$TABLE.ibd" ]; then
|
||||
if [ ! $(innochecksum $DIR/$BDD/$TABLE.ibd) ]; then
|
||||
|
@ -180,6 +187,8 @@ OPTIONS:
|
|||
-e Exclude databases
|
||||
-s Selected databases
|
||||
-c Check innochecksum of table after import
|
||||
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
|
|
|
@ -69,38 +69,46 @@ restore()
|
|||
fi
|
||||
|
||||
if [ -s "$DIR/$TABLE.txt" ]; then
|
||||
f_log "+ $TABLE"
|
||||
|
||||
if [ ! -z "$(cat $DIR/$BDD/$TABLE.sql | grep -i 'DEFAULT CHARSET=CP1251')" ]; then
|
||||
charset='cp1251'
|
||||
else
|
||||
charset='utf8'
|
||||
fi
|
||||
|
||||
f_log "+ $TABLE, Set default charset: $charset"
|
||||
|
||||
split -l $CONFIG_CHUNK "$DIR/$TABLE.txt" "$DIR/${TABLE}_part_"
|
||||
for segment in "$DIR/${TABLE}"_part_*; do
|
||||
f_log "Restore from $segment"
|
||||
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;
|
||||
LOAD DATA LOCAL INFILE '$segment'
|
||||
INTO TABLE $TABLE;
|
||||
SET foreign_key_checks = 1; SET unique_checks = 1; SET sql_log_bin = 1;"
|
||||
split -l $CONFIG_CHUNK "$DIR/$TABLE.txt" "$DIR/${TABLE}_part_"
|
||||
for segment in "$DIR/${TABLE}"_part_*; do
|
||||
f_log "Restore from $segment"
|
||||
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;
|
||||
SET character_set_database = $charset;
|
||||
LOAD DATA LOCAL INFILE '$segment'
|
||||
INTO TABLE $TABLE;
|
||||
SET foreign_key_checks = 1; SET unique_checks = 1; SET sql_log_bin = 1;"
|
||||
|
||||
if [ -f "$segment" ]; then
|
||||
f_log "Delete segment $segment"
|
||||
rm "$segment"
|
||||
fi
|
||||
done
|
||||
if [ -f "$segment" ]; then
|
||||
f_log "Delete segment $segment"
|
||||
rm "$segment"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -f "$DIR/$TABLE.txt.bz2" ]; then
|
||||
f_log "Delete source file: $TABLE.txt"
|
||||
rm $DIR/$TABLE.txt
|
||||
fi
|
||||
if [ ! -f "$DIR/$TABLE.txt.bz2" ]; then
|
||||
f_log "Delete source file: $TABLE.txt"
|
||||
rm $DIR/$TABLE.txt
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $DATABASES_TABLE_CHECK ]; then
|
||||
if [ -f "$DIR/$BDD/$TABLE.ibd" ]; then
|
||||
if [ ! $(innochecksum $DIR/$TABLE.ibd) ]; then
|
||||
f_log "$TABLE [OK]"
|
||||
else
|
||||
f_log "$TABLE [ERR]"
|
||||
if [ $DATABASES_TABLE_CHECK ]; then
|
||||
if [ -f "$DIR/$BDD/$TABLE.ibd" ]; then
|
||||
if [ ! $(innochecksum $DIR/$TABLE.ibd) ]; then
|
||||
f_log "$TABLE [OK]"
|
||||
else
|
||||
f_log "$TABLE [ERR]"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
|
@ -137,6 +145,8 @@ OPTIONS:
|
|||
-e Exclude databases
|
||||
-s Selected databases
|
||||
-c Check innochecksum of table after import
|
||||
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue