#!/bin/bash

Home=/home/simon
GitLocalRoot=${Home}/local.git
EmsBEDir=${GitLocalRoot}/ems.agt
user="root"
password="1000omc@kp!"
host="192.168.2.119"
port="33066"
dbname="omc_db"
dumpdbdir=${EmsBEDir}/tools/misc
insdir=${EmsBEDir}/database/install
upgdir=${EmsBEDir}/database/upgrade
tables_c=tables_c.lst
tables_s=tables_s.lst

#mysql -u ${user} -p${password} -D ${dbname} -e "show tables ; " > tables.lst

# dump table struct and data
while read line
  do
    table=`echo $line | cut -d " " -f 1`
    echo "dump ${table} to install & upgrade directory"
    mysqldump -h ${host} -P ${port} -u ${user} -p${password} ${dbname} ${table} > ${insdir}/${table}.sql
    mysqldump -h ${host} -P ${port} -u ${user} -p${password} ${dbname} ${table} > ${upgdir}/${table}.sql
  done < ${dumpdbdir}/${tables_c}

# dump table struct
while read line
  do
    table=`echo $line | cut -d " " -f 1`
    echo "dump ${table} to install directory"
    mysqldump -h ${host} -P ${port} -u ${user} -p${password} -d ${dbname} ${table} > ${insdir}/${table}.sql
  done < ${dumpdbdir}/${tables_s}
