Web Designer, Developer, Entrepreneur
How to use rsync: A simple tutorial on managing files on a remote server
How to use rsync: A simple tutorial on managing files on a remote server
Submitted by david on Sat, 07/03/2010 - 10:49Managing a remote server can be a daunting task when just starting out; figuring out how to upload files, update changes, make backups, etc. This is where rsync comes in. It's a tool I'm sure almost every serious developer is aware of, and one I think every beginner should learn to use. I've recently (very recently) learned how to use rsync and it's already saved me time and headaches for updating remote servers.
It's important to note that rsync needs to be installed on both the remote server as well as you local computer. For Mac users, at least for Snow Leopard, rsync is pre-installed and ready to go. My experience with installing rsync on a linux server has been as easy as typing sudo apt-get install rsync. That's it!
The command is simple:
rsync -avz -e ssh /path/to/local/dir/* user@example.com:/path/to/remote/dir
For example:
rsync -avz -e ssh /Users/david/Sites/davidtiede.com/* administrator@davidtiede.com:/var/www/davidtiede.com
Note: Be sure to add the /* to the local directory path to ensure only the contents of that path are uploaded, and not the directory itself. Not adding it will create a directory /var/www/davidtiede.com/davidtiede.com instead.
The -avz breaks down as follows:
-a: Archive; keeps the same permissions for files and folders
-v: Verbose; gives you some feedback on the progress of the upload (see also --progress and --stats for more info)
-z: Compress; simply compress the files for sending
-l: Links; if you have any links in your folders, be sure to add this one as well
-e ssh: Ensures you only transfer files with an encrypted connection
There's also a handy -update command when all you want to do is update any changes. For example:
So what are you waiting for? Give it a try!
- david's blog
- Login to post comments