Fun with Rsync over ssh

Sync

Continuing on the blog subject, now I need to sync my local blog folder to the server's remote folder so that when I have done writing a new article it may be seen on the server as well.

First I thought, I need to setup a FTP service on the server. But, I hate to open ports :) and anyways I already have the open-ssh service running which I could use as a tunnel. And since I already setup the ssh public key login, it should be very easy to transfer stuff from a local folder to the server. I could even use scp to do it, and it works well but what's great with rsync is that it can transfer only what needs to be transferred.

Rsync mirror

So I ended with creating a script which I have put in ~/bin

#!/bin/bash
rsync -avz --delete -e ssh --progress ~/_Development/blog/ $MCC:dev/blog/draft && ssh $MCC -x -- cd dev/blog \&\& rm published/\* \; mv draft/\* published/

$MCC is export'ed and is the address of the server

You may notice that I do a sync into the draft folder and then move it to the destination so that even if the rsync process takes a long time, the nodejs fs.watch on the published/ folder of the blog, which updates the blog, will not read half transfered files.