时间:2021-07-01 10:21:17 帮助过:12人阅读
目前的用户名,密码,host都是写死在脚本里,这样比较方便,有需要的朋友可以把他改成读参数的,
或者是windows风格的下一步
#!/bin/basht=`date +%Y%m%d_%H%M`p_user=rootp_pwd=123456p_host=127.0.0.1#从数据库中读出表结构echo 'select SCHEMA_NAME from SCHEMATA ' > sql#p_all_db=(gzcore gzchar gzrealmd gzshop)p_all_db=(`mysql -h${p_host} -u${p_user} -p${p_pwd} information_schema < sql`)rm sql#如果文件夹存在则删除#[[ -d ${p_host} ]] || rm -rf ${p_host}#创建新文件夹mkdir ${p_host} 2>/dev/nullcd ${p_host}#生成for i in ${p_all_db[*]}do if [ "SCHEMA_NAME" = $i ] || [ "information_schema" = $i ] || [ "mysql" = $i ];then echo "skip ${p_host} $i" continue else echo "bak ${p_host} $i .." rm -f ${PWD}/${i}_${t}.dump 2>/dev/null mysqldump -u${p_user} -p${p_pwd} -h${p_host} --databases $i > ${PWD}/${i}_${t}.dump fidone#返回原来的路径cd ..