Pages Menu
Categories Menu

Posted by on Dec 2, 2011 in Linux | 0 comments

Publish Through SSH with rsync

I was doing a web project for a client recently where I needed to publish project files to the server but only had access to the machine via port 22 (ssh). The rsync command proved to be invaluable. Rsync is similar to scp but it synchronizes files and directories from one location to another.

You can also copy files through SSH which solved my problem. As an added bonus, after the initial rsync, it only transfers files which have been modified rather than transferring everything each time like you would get with ftp, Xcopy,  or similar.

Using rsync, I could sync my project files with the document root of the webserver with a single command.

To use rsync on a Windows machine, you will need to install Cygwin with the OpenSSL package.

# Sync contents of project folder to remote document root folder via ssh
# Note the use of the --exclude here so rsync will not copy any svn files
rsync -avz -e ssh --exclude=.svn /srcPath/ root@<IpAdd>:/destPath/

# try it with --dry-run first to make sure you don’t do something stupid!
rsync --dry-run -avz -e ssh --exclude=.svn /srcPath/ root@<IpAdd>:/destPath/