DBA SHELL脚本
$ cat dataManager.sh
#!/bin/bash
read -p "请输入开始备份数据库位点:" begin
read -p "请输入结束备份数据库位点:" end
flag_time(){
date +"%Y-%m-%d_%H.%M.%S"
}
flag_timestamp(){
date +"%s"
}
db_dir=/u01/mysql/data
dbs=$(ls -l $db_dir|egrep -v "total"|awk '{print $NF}'|sed -n "$begin,$end p")
db_list=()
db_list+=("$dbs")
echo "${db_list[*]}" > db_list.temp_${begin}-${end}
echo '开始传输时间:' $(flag_time)
for f1 in $(cat db_list.temp_${begin}-${end})
do
echo "!!!db: "$f1 " start_time:" $(flag_time)
start_s=$(flag_timestamp)
#sleep 2
#####scripts
scp -r $db_dir/$f1 10.130.160.100:/u01/mysql/data/
end_s=$(flag_timestamp)
echo $f1 "spent time:" $((end_s-start_s))"s"
done
echo '传输完成时间:' $(flag_time)
#rm db_list.temp_${begin}-${end}