cat << 'EOF' > ~/.my.cnf
[client]
host=127.0.0.1
user=root
password=zabbix
EOF
for table in $(ls -1r) ; do {
mysql zabbix -e "show tables;" | grep -c $(echo $table | sed "s|^[0-9]\+\.||;s|\..*$||")
if [ $? -eq 0 ]; then
echo yes: $(echo $table | sed "s|^[0-9]\+\.||;s|\..*$||")
else
echo no: $(echo $table | sed "s|^[0-9]\+\.||;s|\..*$||") not exists
mysql zabbix -e "CREATE TABLE $(echo $table | sed "s|^[0-9]\+\.||;s|\..*$||") LIKE $(echo $table | sed "s|^[0-9]\+\.||;s|\..*$||" | sed "s|_old||");"
fi
echo $table
zcat $table | mysql zabbix
} done
After restore:
SET SESSION SQL_LOG_BIN=0;
RENAME TABLE history_uint TO history_uint_tmp; RENAME TABLE history_uint_old TO history_uint; INSERT INTO history_uint (SELECT * FROM history_uint_tmp); DROP TABLE history_uint_tmp;
RENAME TABLE history_log TO history_log_tmp; RENAME TABLE history_log_old TO history_log; INSERT INTO history_log (SELECT * FROM history_log_tmp); DROP TABLE history_log_tmp;
RENAME TABLE history_text TO history_text_tmp; RENAME TABLE history_text_old TO history_text; INSERT INTO history_text (SELECT * FROM history_text_tmp); DROP TABLE history_text_tmp;
RENAME TABLE history_str TO history_str_tmp; RENAME TABLE history_str_old TO history_str; INSERT INTO history_str (SELECT * FROM history_str_tmp); DROP TABLE history_str_tmp;
RENAME TABLE history TO history_tmp; RENAME TABLE history_old TO history; INSERT INTO history (SELECT * FROM history_tmp); DROP TABLE history_tmp;
RENAME TABLE trends_uint TO trends_uint_tmp; RENAME TABLE trends_uint_old TO trends_uint; INSERT INTO trends_uint (SELECT * FROM trends_uint_tmp); DROP TABLE trends_uint_tmp;
RENAME TABLE trends TO trends_tmp; RENAME TABLE trends_old TO trends; INSERT INTO trends (SELECT * FROM trends_tmp); DROP TABLE trends_tmp;
No comments:
Post a Comment