#!/bin/bash
cd ..
export CUR_PATH=$(pwd)
cd mysql-test
export CLIENT_PATH=$CUR_PATH/bin
export MTR_BUILD_THREAD=74
perl ./mysql-test-run.pl --start --mysqld=--secure-file-priv= --mysqld=--innodb --mysqld=--log-output=file --mysqld=--default-storage-engine=innodb rpl_alter &
sleep 10
echo "$(date) - Creating the Flight_Stat_test database and schema"
$CLIENT_PATH/mysql --user=root --port=10740 --protocol=tcp < ./bug_files/cr_fl_schema.sql
echo "$(date) - Altering the tables"
$CLIENT_PATH/mysql --user=root --port=10740 --protocol=tcp < ./bug_files/cr_fl_alter.sql
echo "$(date) - Loading the data"
#$CLIENT_PATH/mysql --user=root --port=10740 --protocol=tcp < ./bug_files/bug_load.sql
$CLIENT_PATH/mysql --user=root --port=10740 --protocol=tcp <<END_OF_SQL
   use FlightStats_test;
   load data infile '$CUR_PATH/mysql-test/bug_files/ontime_1week.dat' 
      into table ontime_1week fields terminated by '\t' lines terminated by '\n';
   load data infile '$CUR_PATH/mysql-test/bug_files/ontime_1week.dat' 
      into table ontime_all fields terminated by '\t' lines terminated by '\n';
END_OF_SQL

echo "$(date) - Adding procedures triggers  and IUDS tables"
$CLIENT_PATH/mysql --user=root --port=10740 --protocol=tcp < ./bug_files/cr_fl_iuds.sql
sleep 10

echo "$(date) - Started IUDS clients (in the background)"
rm -r stress > /dev/null
mkdir stress
  (./mysql-stress-test.pl --stress-basedir=$CUR_PATH/mysql-test/stress \
                          --stress-suite-basedir=$CUR_PATH/mysql-test \
                          --server-logs-dir=$CUR_PATH/mysql-test/stress \
                          --stress-tests-file=run_iuds.txt \
                          --server-user=root --server-port=10740 --server-host=127.0.0.1 \
                          --mysqltest=$CLIENT_PATH/mysqltest \
                          --test-duration=120 --threads=20 > ./stress/run.out 2>&1 
   echo "$(date) - IUDS client run completed"
   ) &

sleep 30

echo $(date) - Running a backup
rm $CUR_PATH/mysql-test/fl_bk.bck
$CLIENT_PATH/mysql --user=root --port=10740 --protocol=tcp -e"backup database FlightStats_test to '$CUR_PATH/mysql-test/fl_bk.bck';"
echo $(date) - Backup done

#./run_backup

