华为ant命令实例

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

华为ant命令实例
我们要先把本地的文件压缩到一个压缩文件中,实现增量部署的关键也是在这里。

最好的方式是每次只压缩最近修改的内容,而那些没有修改的内容没有必要再次上传。

压缩一个时间点以后的文件可以通过date来实现,不过我们需要自动的记录上一次部署的时间。

现在有两种方式可以做这件事,一种是付成睿的,比较简单,但会修改配置文件;另外一种就是我的方式,也就是将日期保存到一个文件中,如果没有文件就认为是全部部署,并创建文件。

具体的代码如下:
<target name="appZipModified">
<!-- 判断文件是否存在 -->
<condition property="local.app.timestamp.present">
<available file="${app.zip.timestamp.file}" type="file" />
</condition>
<!-- 如果文件不存在则创建文件 -->
<antcall target="mkStampFile">
<param name="zipFilePresent"
value="${local.app.timestamp.present}" />
<param name="newZipFile"
value="${app.zip.timestamp.file}" />
</antcall>
<echo>Load the old timestamp from the disk file</echo>
<loadfile property="old.zip.timestamp"
srcFile="${app.zip.timestamp.file}" />
<!-- 获取当前时间 -->
<tstamp>
<format property="this.zip.timestamp"
pattern="${ts.pattern}" />
</tstamp>
<echo>zip the new modified files &amp; folders that after ${old.zip.timestamp} to ${appzip} </echo>
<delete file="${appzip}" />
<!-- 执行压缩操作 -->
<zip destfile="${appzip}">
<fileset dir="../WebRoot">
<include name="**/*" />
<date datetime="${old.zip.timestamp}"
pattern="${ts.pattern}" when="after" />
</fileset>
</zip>
<echo>Replace the old timestamp with the new
timestamp</echo>
<!-- 最后将当前的时间更新到文件中 -->
<replace file="${app.zip.timestamp.file}"
token="${old.zip.timestamp}" value="${this.zip.timestamp}" />
</target>
<target name="mkStampFile" unless="zipFilePresent">
<echo>Create txt file to store timestamp</echo>
<!-- 创建一个文件 -->
<touch file="${newZipFile}" datetime="12/19/2007 21:20 pm" />
<!-- 应用正则表达式的replace命令,写入一个很早的时间(正则真是太神奇了!) -->
<replaceregexp file="${newZipFile}" match=".*"
replace="2000.01.01 00:00:00" byline="true" />
</target>
下面的例子是将文件解压缩,最关键的是sshexec命令的用法。

<!-- 解压缩备份文件 -->
<target name="unZipBackupResource" description="decompress the backup tar file back to the file system">
<echo>decompress the backup tar file back to the file system</echo>
<sshexec host="${host}" username="user" command="tar xvf test.tar" password="${pass}" trust="yes" />
</target>
这就是完整的流程。

相关文档
最新文档