#!/bin/sh
set -x
data=`date +%Y%m%d%H%M`
mkdir /bak/backup/db/bak3307_$data/
dir1=/usr/local/mysql516-3307/bin/
dir2=/bak/backup/db/bak3307_$data/
dir3=/usr/local/mysql516-3303/bin/
cd $dir1
./mysql -uroot -p1233307 -S /tmp/mysql3307.sock <<EOF > /bak/backup/db/tables_3307.txt
show databases like 'xy%test';
EOF
for i in `cat /bak/backup/db/tables_3307.txt`
do
./mysqldump -uroot -p1233307 -S /tmp/mysql3307.sock $i > $dir2$i.sql
done
cd $dir3
./mysql -uroot -p123 -S /tmp/mysql3303.sock
for file1 in $dir2
do
./mysql -uroot -p123 -S /tmp/mysql3303.sock < $file1
done
#读取$dir2文件夹中的每一个文件
set +x