14

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.

Andrew Redd
  • 1,289

3 Answers3

12

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).

5

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.

killermist
  • 1,601
tante
  • 6,350
  • 1
  • 28
  • 23
  • 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
  • http://www.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 'SO- stop being evil' Sep 29 '10 at 22:41
  • 1
    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
1

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
  • ...
echox
  • 18,103
  • 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 09:02