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.

categories Mac, Web Design
tags rsync, ssh

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.

8 Responses to “rsync to remote server via ssh”

  1. #1 Wez responds...
    March 1st, 2005 at 4:30 pm

    rsync works both ways; pushing and pulling data.

  2. #2 John McAdams responds...
    March 1st, 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. #3 Sencer responds...
    March 1st, 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. #4 Bill Lovett responds...
    March 1st, 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 pingbacked on March 15th, 2005 at 9:41 am
  6. #6 Mike responds...
    March 24th, 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 pingbacked on April 1st, 2005 at 8:10 am
  8. #8 James responds...
    May 19th, 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.

Leave a 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

  • Search

  • Subscribe

    Subscribe All Posts
    Subscribe All Comments
    Subscribe All Bookmarks
    Subscribe with Bloglines Subscribe with My Yahoo Add to netvibes Subscribe in NewsGator Online Add to Google
  • Share This

  • Categories (Home)

    • Agile Methods (14)
    • Mac (14)
    • Misc (16)
    • Open Source (14)
    • PHP (95)
    • Software Design (28)
    • Usability (14)
    • WACT (7)
    • Web Design (20)
  • Recent Comments

    • Working with PHP 5 in Mac OS X 10.5 (Leopard)  94
      noujoum, Michiel Van Kets, isorabins [...]
    • Sarah Snow Stever  24
      Dubai Web Design, Development, Snowcore, ennah [...]
    • Benchmarking PHP's Magic Methods  8
      stas, minikperi, Shelon Padmore [...]
    • Keywords and Language Simplicity  7
      olmse, Handy, minikperi [...]
    • Even the Big Guys Get Validation Wrong  4
      James Benson, Michael, Enric Naval [...]
    • Improved Error Messages in PHP 5  12
      James Benson, Iron, baggreeddog [...]
    • How to Transfer Mac OS X Application Data between Computers  36
      Secret Santa, micala, Khaled bin Alwaleed [...]
    • Programming Language Trends via Google  15
      MattW, Jeff Davis, retry [...]
    • PHP Development From Java Architects Eye  10
      Grrkkvho, Bobrila, FelhoBacsi [...]
    • The value of MVC  9
      Euvmetkk, Bobrila, Vulchak [...]
    • nofollow and comment spam  5
      Scopmazo, Qmumqckx, sss [...]
  • Pages

    • Tags
  • Recent Posts

    • 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)
    • Keywords and Language Simplicity
    • Improved Error Messages in PHP 5
    • Michigan Taxes Graphic Design Services
    • Ruby versus PHP or There and Back Again
  • Archives

    • 2008: May
    • 2007: Jan Feb Mar Apr May Sep Oct Nov
    • 2006: Jan Feb Mar Apr May Jun Jul Oct Nov Dec
    • 2005: Jan Feb Mar Apr May Sep Oct Nov Dec
    • 2004: Apr May Jun Jul Aug Sep Oct Nov
  • Menu

    • Register
    • Log in