6
votes

I would like to optimize my scp deployment which currently copies all files to only copy files that have changed since the last build. I believe it should be possible with the current setup somehow, but I don't know how to do this.

I have the following:

Project/src/blah/blah/ <---- files I am editing (mostly PHP in this case, some static assets)

Project/build <------- I have a local build step that I use to copy the files to here

I have an scp task right now that copies all of Project/build out to a remote server when I need it.

Is it possible to somehow take advantage of this extra "build" directory to accomplish what I want -- meaning I only want to upload the "diff" between src/** and build/**. Is it possible to somehow retrieve this as a fileset in ANT and then scp that?

I do realize that what it means is that if I somehow delete/mess around with files on the server in between, the ANT script would not notice, but for me this is okay.

2
To clarify, I want it to basically do what the regular copy task does with incremental copying.Artem

2 Answers

15
votes

You can tell ant scp to only copy files which have been modified since the last push using the modified tag like so:

<scp trust="true" sftp="true"... >
  <fileset dir="${local.dir}">
    <modified>
      <param name="cache.cachefile" value="localdev.cache"/>
    </modified>
  </fileset>
</scp>

The first time you use this, it will send all files and cache the timestamps in the cachefile declared in the param. After that, it will only send the modified ones.

Tested and verified in sftp mode.

0
votes

I think you need to use rsync instead. I found the following article that answers your question.

In a nutshell rsync will resume where it left off and it should be possible to tunnel it over ssh.