Professional PHP

PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.
« Flawed Microbenchmarks
Writing an XPath expression evaluator »

rsync to remote server via ssh

March 1st, 2005

If you ever need to repeatedly upload to a remote server, here is the command line of the day:

rsync -zrptL --delete-after -e "ssh"  --include=core --include=tags --exclude=.DS_Store --cvs-exclude /local/dir user@host:/remote/dir/

rsync sends only the files that have changed. I just tried rsync today for the first time and I’m impressed. Its far faster than all of the ftp based synchronization tools I’ve used. Unfortunately, it only goes in one direction. Here are the meanings of the options:

z – use compression
r – recurse directories
p – preserve permissions
t – preserve times
L – copy (flatten) symbolic links

–delete-after – gets rid of any files in the remote directory that are not in the local directory. It prevents old files from getting orphaned on the server.

Put any ssh parameters you need inside the quotes.

I develop on Mac OS X, so –exclude=.DS_Store gets rid of those annoying little files.

–cvs-exclude gets rid of all the crud that CVS leaves lying around.

–include=core and –include=tags are my very hard won lesson of today. My program has a core and a tags directory. Tags is a special directory for cvs and removed by the –cvs-exclude option. Any file or directory named core is also removed by this option. –include puts em back. The other –cvs-exclude patterns are less likely to collide. I think –include has to come before the –cvs-exclude on the command line.

The trailing slash (or absence of one) on the source and destination directories matter.

Filed Under

  • Mac, Web Design

Related Posts

  • Knocked off the internet, a story of Windows and Macintosh
  • Web Page Loading Performance
  • A Comparison of the PHP and Java Job Markets
  • Manual Memory Management is Dead
  • PHP Games
You can leave a response, or trackback from your own site.

9 Responses to “rsync to remote server via ssh”

  1. Wez says:
    3/1/2005 at 4:30 pm

    rsync works both ways; pushing and pulling data.

  2. John McAdams says:
    3/1/2005 at 7:03 pm

    rsync goes up and down. To sync from remote to local just reverse the source and destination.

    Try this link for a nice shell script and a modified version of rsync that can handle HFS+ resource forks. .

  3. Sencer says:
    3/1/2005 at 7:45 pm

    Take a look at Unison:
    http://www.cis.upenn.edu/~bcpierce/unison/

    It’s for synchronizing and also implements the rsync-algo for efficient bandwidth usage.

  4. Bill Lovett says:
    3/1/2005 at 8:44 pm

    Look into Unison. It’s like rsync, but works in both directions.

    http://www.cis.upenn.edu/~bcpierce/unison/

  5. Jeff Moore’s Blog » Blog Archive » Knocked off the internet, a story of Windows and Macintosh says:
    3/15/2005 at 9:41 am

    [...] ter now, but I still decided that I didn’t want to try that route. Besides, I just got my automated deployment scripts working on the Mac. So Monday morni [...]

  6. Mike says:
    3/24/2005 at 4:10 pm

    From the root of my project, I use:
    rsync -avzu –exclude-from=rsync-exclude.txt * host:`pwd`

    from my development server to the live server where the paths are the same.

    I list a bunch of files in rsync-exclude.txt like images used only in production, files like CHANGELOG, etc. This file gets added to my CVS repository with each project.

    I don’t use the –cvs-exclude because i tag my project before a release/upload and `cvs export -r TAGNAME project` so you won’t have CVS/ directories, etc.

    The -n option is great and I encourage you use it before running it without. It will print you a list of all the files it wants to upload, allowing you to double check that you are about to upload anything by accident.

  7. JTK - Notes and Ramblings » Blog Archive » Jeff Moore%u2019s Blog � Blog Archive � rsync to remote server via ssh says:
    4/1/2005 at 8:10 am

    [...] Jeff Moore%u2019s Blog � Blog Archive � rsync to remote server via ssh Jeff Moore%u2019s Blog � Blog Archive � rsync to remote server vi [...]

  8. James says:
    5/19/2005 at 12:10 am

    –exclude-cvs considered harmful.

    Well, it’s harmed me at least. Consider the case where you’re editing files on a ‘remote’ machine prior to committing them via a central machine ‘closer’ to the CVS repository(*).

    Consider the following: you cvs update, rsync ‘away’ to another machine and do some editing there, cvs update again (whoops), then then rsync ‘back’ (disaster). You’ve now got ‘CVS/entries’ that say you’ve got the most recent files on the central system, but you’ve actually just rsync’d old versions of the files back. CVS will think you’re trying to ‘un-modify’ all the files back to where they were when you first CVS updated.

    If you always keep the CVS meta files with the files they relate to, that sequence of events will simply result in CVS complaing you have state files.

    Trust me. If you think you can simply just remember where you are and always update/sync in the right order, you’re kidding yourself. If you’re rsyncing checked-out CVS trees, its far too easy to mess up: blow the cost: sync your CVS meta data!

    (*) pserver seems like a solution here, but consider the case where you need to test code on more than one platform *before* committing the code.

  9. Burton Haynes says:
    3/5/2010 at 11:18 pm

    Thanks for this post, answers a bunch of questions I was having.

Leave a Reply

Click here to cancel reply.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

code: use [code=php][/code].

Comment Preview

    Subscribe Feed
    Share Subscribe to this blog…
    Share Bookmark or share this page…
  • About

    My name is Jeff Moore. I'm a PHP programmer living in San Francico and working for a startup.

    More about me…

  • Categories (Home)

    • Agile Methods (14)
    • Mac (14)
    • Misc (17)
    • Open Source (14)
    • PHP (98)
    • Software Design (29)
    • Usability (14)
    • Web Design (20)
  • Recent Comments

    • Benchmarking PHP's Magic Methods  12
      Article Marketing Strategy, Magento Development, Vance Lucas [...]
    • Improved Error Messages in PHP 5  32
      Terry Nessel, css, Amsterdam [...]
    • Keywords and Language Simplicity  11
      kim kardashian sex tape price, nokia, per Rechnung bestellen [...]
    • flickr case study  3
      bookmarking demon software, php-trivandrum.org, Harry Fuecks
    • rsync to remote server via ssh  7
      Burton Haynes, James, Mike [...]
    • Yahoo YUI wins JavaScript Library Wars  10
      Lera Bride, Scott, Jeff [...]
    • OOP is Mature, not Dead  15
      Avery Depew, Fernando, deltawing [...]
    • Ruby versus PHP or There and Back Again  10
      Solar Pumps, Amsterdam, Hari K T [...]
    • Looking Towards the Cloud  22
      Driver License, Jamel Sawyer, enculez. [...]
    • ZendCon: Writing Maintainable PHP Code  8
      IT Ninja, nicopico, Arif [...]
  • Recent Posts

    • ZendCon: Writing Maintainable PHP Code
    • Looking Towards the Cloud
    • Holiday Tech Support
    • Closures are coming to PHP
    • php | tek Wrapup
    • php | tek 2008
    • Sarah Snow Stever
    • Benchmarking PHP’s Magic Methods
    • The Endpoints of the Scale of Stupidity on Video
    • Working with PHP 5 in Mac OS X 10.5 (Leopard)
  • Site

    • Archives
    • Log in
  • Search