#!/bin/bash # Temporary root folder that contains data sent by xtrabackup TMPDIR="/tmp/test" # mysql root DESTDIR="/srv/mysql" # tmp database (that contains all tables) TMPDB="test" # destination database DESTDB="mydb" cd $TMPDIR"/"$DESTDB if [ $(/bin/ls *.exp |wc -l) == "0" ]; then echo "Data seems not prepared (need .exp files)" exit -1; fi for table in $(/bin/ls *.ibd); do table=${table%.*} printf "%20s " $table; echo -n "create/alter: "; echo "SET FOREIGN_KEY_CHECKS = 0; \ CREATE TABLE \`"$table"\` LIKE \`"$TMPDB"\`.\`"$table"\`; \ ALTER TABLE \`"$table"\` DISCARD TABLESPACE;" \ | mysql $DESTDB; if [ $? != "0" ]; then echo -e "\nError caught, exiting." exit -1; fi echo -n "OK "; echo -n "ibd_mv: "; /bin/mv ${table}.ibd ${table}.exp $DESTDIR/$DESTDB if [ $? != "0" ]; then echo -e "\nError caught, exiting." exit -1; fi echo -n "OK "; echo -n "import_tb: "; echo "ALTER TABLE \`"$table"\` IMPORT TABLESPACE;" \ | mysql $DESTDB; if [ $? != "0" ]; then echo -e "\nError caught, exiting." exit -1; fi echo -n "OK "; echo ""; done