Ssh & tar to incrementally transfer (like rsync)

backuprsyncsshtar

In a hosting environment that has no rsync client, I'd like to perform an action similar to what rsync does: send only those files that have changed.

I would perform this one-liner on the current directory. This updates the archive.tar.gz with changed files, then scp the file to remote site and finally unpack it leaving synced directories. I have the vision of this using multiple pipes but I suppose I'll need an archive to actually use the incremental feature.

I'm getting lost on the tar syntax when using incremental.

Best Answer

bozosync.sh

Hmm, if you only want to move the changed files, why would the tar command be updating the archive? If only changed files are being sent, wouldn't the tar archive consist only of them, and so be necessarily recreated from scratch each time?

If I'm understanding this correctly you want something like this, I call it bozosync.sh:

TarFile=fun.tgz
TheScript=$0
result=
ls -1 . | (
  while read f; do
    if [ -f "$f" -a $f -nt $TheScript ]; then
      result="$result $f"
    fi
  done
  tar cvfz $TarFile $result
  touch $TheScript
)

This puts every plain file in the current directory in the tar archive, for each file that is newer than the script itself, and then it runs touch(1) on the script to update its mod time. This does have a race condition, in that a file that is modified in between the test and the touch will be ignored the next time around. If this is a problem you could get around that by copying the script prior to the loop, and then moving it back to itself at the end. (Then you still have a race but the failure is softer, it may simply include a file that hasn't really changed.)