rsync - synchronize web server and your local computer July 20, 2006
Posted by Slobodan Kovacevic in : Resources and Links , trackbackWhen developing sites it’s always a pain to upload updates on server, i.e. to synchronize server with local copy of the files. This is especially true if you have a site which you don’t keep under version control (although there is no good reason for that) or if your hosting company doesn’t have CVS / SVN client installed so you cannot simply update server working copy. So usually you are best of always uploading the whole site.
But if you have SSH access to your server (and most decent hosting companies will give you SSH) you may use rsync to upload only changed files from your local computer to server. If you have Linux you probably already have rsync and if you use Windows you’ll need to use Cygwin (just look at any of these for Windows rsync install instructions).
The command itself looks like this:
rsync -e ssh -av /path/to/local/copy/ yourusername@yourserver.com:/path/to/www/server/copy/
When you execute (obviously you’ll have to change command a bit to reflect your real paths) it will ask you for your password and upon login you’ll get something like this:
building file list ... done ./ production.php sound_and_light.php specialist.php user-edit-process.php user-logout.php user-sendemail.php sent 1942 bytes received 158 bytes 113.51 bytes/sec total size is 1692 speedup is 0.81
That’s it, files on your server have been updated and they are exactly the same as those on your local computer.
Main advantage when using rsync is that it will only upload files that have been changed, so you won’t have to upload everything whenever you want to update server files - this will save you a lot of time.
Although command might seem complicated it’s actually pretty straight forward. You are just telling rsync that you want to synchronize first dir with second one which happens to be on server. It also contains couple options:
‘-e ssh’ - tells it to use ssh to connect to your server.
‘-av’ - tells it to be verbose and use something called ‘archive mode’ (which basically says you want to copy everything in this dir and to preserve file time stamps).
You can also use rsync for much more than this, for example you can synchronize two servers, set it up to run as cron script to perform daily synchronization / backup or even just make local backup copies of your files.
Comments»
no comments yet - be the first?