zoukankan      html  css  js  c++  java
  • Jenkins基础篇 系列之-—08 实现SQL脚本批量执行补充

    对前一篇的优化,补充单脚本执行成功就及时备份,原来这里是模块备份
    Jenkins基础篇 系列之-—07 实现SQL脚本批量执行

    Ant知识

    官网说明
    在ant中,无法实现常见的字符重操作,比如截取、替换。我们可以借助ant-contrib中的propertyregex任务实现字符串的截取、替换

    1、字符串的截取

    <!--${file.separator} 文件分割符 ,windows   ,linux  /  -->
    
     <propertyregex property="result"
                  input="D:apache-ant-1.9.6-binliba.txt"
                  regexp="([^*]*)${file.separator}"
                  select="1"
                  casesensitive="false" />
     <echo>文件绝对路径:${result}</echo>
     <propertyregex property="result" 
                input="D:apache-ant-1.9.6-binliba.txt" 
                regexp="[^${file.separator}]+$" select="" 
                casesensitive="false"/>
     <echo>文件名:${result}</echo>
    

    2、字符串的替换

    比如:替换字符串root:password@127.0.0.1为root:pwd@127.0.0.1
    
     <propertyregex property="${svr1}" input="${svr}" regexp='password' replace="pwd"/>
    

    Target优化

     <target name="runSqlInFolder">
    	<echo>Run the SQL at Folder: ${sqlfolder}</echo>
    	<echo>DB Host: ${v7testdb.host}</echo>
    	<echo>DB Name: ${v7testdb.name}</echo>
    	<echo>DB User: ${v7testdb.user}</echo>
    	<trycatch property="errMsg">
    		<try>
    			<for param="file">
    				<path>
    					<sort xmlns:rcmp="antlib:org.apache.tools.ant.types.resources.comparators">
    						<fileset dir="${sqlfolder}" includes="*/*/*.sql" casesensitive="false"/>
    					</sort>
    				</path>
    				<sequential>
    					<echo>SQL: @{file}</echo>
    					<propertyregex override="yes" property="sqlFolderName" input="@{file}"
    						regexp="${sqlfolder}${file.separator}([^*]*)${file.separator}" select="1"
    					casesensitive="false" />
    					<propertyregex override="yes" property="sqlFileName" input="@{file}"
    						regexp="[^${file.separator}]+$" select=""
    					casesensitive="false"/>
    						<execsql
    							dbhost="${v7testdb.host}"	
    							dbport="${v7testdb.port}"	
    							dbname="${v7testdb.name}" 
    							dbuser="${v7testdb.user}" 
    							dbpwd="${v7testdb.pwd}"
    							sqlfile="@{file}"
    							logfile="${Sqllogfile}"/>
    					<move file="@{file}" todir="${sqlbakdir}${file.separator}${sqlFolderName}"/>
    				</sequential>
    			</for>
    			<echo>Finished running all SQL</echo>
    			<echo>Files moved to backup folder:${sqlbakdir}</echo>
    		</try>
    		<catch>
    			<echo>Error found when running SQL</echo>
    			<echo>Log file can be found in:</echo>
    			<echo>${sqlbakdir}/err</echo>
    			<move file="${Sqllogfile}" todir="${sqlbakdir}/err"/>
    			<fail>Error Occur</fail>
    		</catch>
    		<finally>
    		</finally>
    	</trycatch>
     </target>
    
  • 相关阅读:
    bzoj3159: 决战
    Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) C
    Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) B
    Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) A
    loj 6401 字符串
    BZOJ5194 雪地靴
    BZOJ 4709 柠檬
    BZOJ 3343 魔法
    [8月16日绍兴]试剂
    设备塔
  • 原文地址:https://www.cnblogs.com/liuyitan/p/12982854.html
Copyright © 2011-2022 走看看