Monday, October 22, 2007

smart files syncronisation using rsync

I work a lot from home using my laptop. Alas, compiling and testing the application requires a very strong machine like the desktop I have at work. So working effectively from home means syncing files back and forth.
The fastest way to do that seems to be rsync, but running the script is a bit slow since I need to modify it each time according to the directory I'm located at. To help with that I wrote two nice scripts which I named 'up' and 'down', and placed them in the path.
One important fact is that I have the same directory structure in the local and remote machines. I.e. I have the same usernames and place the sources in the same place in both machines.

  • When I type 'up' in the command line the script is syncing to the remote machine the current directory with its subdirectory (recursively).
  • When I type 'down' in the command line the script is syncing from the remote machine to the current directory (recursively).
It is very helpful to have ssh without password (i.e. exchange public keys between machines).

Here are the scripts:
up

#!/bin/sh
# Destination host machine name
DEST="myRemoteMachineName"
# User that rsync will connect as
USER="myUserName"
# excludes file - Contains wildcard patterns of files to exclude.
# i.e., *~, *.bak, etc. One "pattern" per line.
# You must create this file.
EXCLUDES=[full path to file]
HERE=$(pwd)
PARENT=$(dirname $(pwd))
OPTS="-v -u -a --rsh=ssh --exclude-from=$EXCLUDES --stats --delete "
rsync $OPTS $HERE $USER@$DEST:$PARENT

down

#!/bin/sh
# Destination host machine name
DEST="myRemoteMachineName"
# User that rsync will connect as
USER="myUserName"
# excludes file - Contains wildcard patterns of files to exclude.
# i.e., *~, *.bak, etc. One "pattern" per line.
# You must create this file.
EXCLUDES=[full path to file]
HERE=$(pwd)
PARENT=$(dirname $(pwd))
OPTS="-v -u -a --rsh=ssh --exclude-from=$EXCLUDES --stats --delete "
rsync $OPTS $USER@$DEST:$HERE $PARENT


Bugs:
Does not work with whitespaces in the path. Tried replacing them with escape characters (see rsync man pages), bit didn't work.

0 comments:

Creative Commons License This work by Eishay Smith is licensed under a Creative Commons Attribution 3.0 Unported License.