Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a folder with a few files in it, and some space on a web server. I want to do a bi-directional sync between the local folder and the remote one in linux, just on modification time. How do I do this? btw I cannot install anything on the server, for all intents and purposes it is just space.

Note: I already have rsa key-pairs set up, so that it can happen silently.

share|improve this question

3 Answers 3

up vote 12 down vote accepted

The tool of choice for unidirectional synchronization is rsync, and the tool of choice for bidirectional synchronization is Unison. Both require the executable to be available on both sides. If you can make a file executable on the server side, drop the unison binary and make it executable.

If you have Linux, *BSD, Solaris or Mac OS X locally, you can probably use a FUSE filesystem to make the web server space appear as a local filesystem — sshfs should work since you seem to have ssh access. Then use unison “locally”.

Also note that most version control software (CVS/Subversion as well as distributed VCS) have synchronization as a by-the-way feature (check in on one machine and out on the other).

share|improve this answer

If it's installed on the server, use rsync it's build for exactly that job.

To get it bi-directional do this (quote from http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1285799008594+28353475&threadId=1278777) :

To bidirectionally sync a directory /src/foo on hostA to /dest/foo on hostB, including all the sub-directories, you would run these commands on hostA:

rsync -auz /src/foo hostB:/dest 
rsync -auz hostB:/dest/foo /src

The first command pushes all the files that are newer on hostA to hostB.

The second command will pull all the files that are newer on hostB to hostA. The critical options are:

when copying, you must preserve file modification times. -a does this and other things;

If you want to preserve just the modification times, use -t instead.

To skip any files that are newer on the destination: -u does this.

share|improve this answer
    
as far as I've read rsync does not do bi directional and when I try to it gives me the error "protocol version mismatch -- is your shell clean?" –  Andrew Redd Sep 29 '10 at 22:14
    
hostanswers.net/linux-hosting/rsync-protocol-version-mismatch might help you fix the version mismatch thing. For the bi-directional thing I updated my answer. –  tante Sep 29 '10 at 22:24
1  
Rsync is not adapted to bidirectional synchronization at all. For one thing it won't warn you if there is a conflict. Use Unison instead, it's the right tool for the job. –  Gilles Sep 29 '10 at 22:41
    
This does break horribly if server A is in the future from server B. In my case, I'm 13 hours ahead of the remote server. –  Tim Post Nov 28 '11 at 10:00

Every time you need a sync between two folders rsync is a great flexible choice. The Problem is, that rsync won't support the ftp protocol. A nice workaround for this is curlFtpFS:

CurlFtpFS is a filesystem for accessing FTP hosts based on FUSE and libcurl.

With curlFtpFs pretty easy to include a remote ftp folder in your filesystem.

This is a short example which shows the usage of both tools:

curlftpfs -r -s ftp.foobar.com /foo
rsync -a /foo/ /bar
umount /foo

Read the manpage for further information.

If you don't want such effort to install curlFtpFS and just want to keep some files in sync, there are lots of ftp tools which offer such sync features:

  • FTPSync.pl - simple PERL script to keep a local and a remote directory in sync
  • weex - a non-interactive FTP client for updating web pages
  • filezilla - GUI FTP client with lots of features
  • ...
share|improve this answer
    
1. Rsync is no good for bidirectional synchronization, use Unison instead. 2. Where did FTP come from? the mention of RSA keys in the question rather suggests ssh (and thus sshfs). –  Gilles Sep 29 '10 at 22:42
    
You are right, FTP is not mentioned in the question. To be honest I think it was a combination of "webspace" and "it is just space." and a bit of my fatigue yesterday. –  echox Sep 30 '10 at 9:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.