Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # usage h2|mysql [mysql_port]
- # 默认的数据端口为 3300
- if [[ ! $1 ]]; then
- echo "usage h2|mysql [mysql_port]"
- exit 1
- fi
- type=$1
- shift
- mysql_port=3300
- if [[ $1 ]]; then
- mysql_port=$1
- fi
- ContextXML=/home/deve/tomcat/conf/Catalina/localhost/context.xml.default
- case ${type} in
- h2)
- echo '即将切入h2模式...'
- # 将配置文件改成h2即可
- sed -i -e "s@market\" url=\"jdbc:mysql@market-mysql\" url=\"jdbc:mysql@g" ${ContextXML}
- sed -i -e "s@market-h2\" url=\"jdbc:h2@market\" url=\"jdbc:h2@g" ${ContextXML}
- ;;
- mysql)
- echo "即将切入mysql模式...使用端口${mysql_port};若脚本执行失败尝试更换端口也许可行。"
- # 即将处理的工作包括有
- # 关闭数据库系统
- # 建立数据库系统
- # 配置数据库系统
- # 建立数据库
- # 导入备份数据
- # 配置文件改成mysql
- # 配置mysql url的端口
- mysqlsh <<EOF
- dba.stopSandboxInstance(${mysql_port},{password:''})
- EOF
- mysqlsh <<EOF
- dba.deleteSandboxInstance(${mysql_port})
- EOF
- mysqlsh <<EOF
- dba.deploySandboxInstance(${mysql_port},{password:''})
- EOF
- #编辑my.conf
- echo 'collation-server=utf8_unicode_ci' >> ~/mysql-sandboxes/${mysql_port}/my.cnf
- echo 'character-set-server=utf8' >> ~/mysql-sandboxes/${mysql_port}/my.cnf
- echo 'lower_case_table_names=1' >> ~/mysql-sandboxes/${mysql_port}/my.cnf
- mysqlsh <<EOF
- dba.stopSandboxInstance(${mysql_port},{password:''})
- dba.startSandboxInstance(${mysql_port})
- EOF
- mysql -u root --port=3300 -h 127.0.0.1 <<EOF
- create database market;
- use market;
- source current_backup.sql;
- EOF
- sed -i -e "s@jdbc:mysql://localhost:(\d+)/@jdbc:mysql://localhost:${mysql_port}/@g" ${ContextXML}
- sed -i -e "s@market-mysql\" url=\"jdbc:mysql@market\" url=\"jdbc:mysql@g" ${ContextXML}
- sed -i -e "s@market\" url=\"jdbc:h2@market-h2\" url=\"jdbc:h2@g" ${ContextXML}
- ;;
- *)
- echo "错误的模式 ${type}"
- exit 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement