I have the following situation: I have multiple client machines (i.e., client1, client2, client3) and I'd like to keep a certain folder ("/code") synchronized across all machines. Currently, I have an rsync script set up on a seperate server to keep the files synchronized. I.e., on the server, I do something like the following:

# Step 1: update/copy all files from each client to the server
rsync -vrtu client1:/code/ /code
rsync -vrtu client2:/code/ /code
rsync -vrtu client3:/code/ /code

# Step 2: synchronize each client with the server
rsync -vrtu /code/ client1:/code
rsync -vrtu /code/ client2:/code
rsync -vrtu /code/ client3:/code

I run this using cron and it propogates any file updates on one machine to all machines. The problem is that deletions are not propagated. Moreover, if I understand the rsync --delete option correctly, it seems that using --delete would keep any new files from my clients from being added to the server. Is that correct? I would just like to keep the files on all three of my clients completely synchronized (additions, deletions, and modifications). Is there a simple way to do what I want using rsync?

1 Answer 1


adding --delete to rsync, will delete the files that are on the receiving side. So there will be nothing to sync in step2. All new files on the clients will already be gone. Rsync --delete will only target the directory being rsynced.

You could use multiple directories. I.e use a dedicated directory for new files on the clients.

You should also consider a version control system like git, for this kind of code synchronization. That way you get cleaner merges if a file on client is changed. You can roll back, use several different branches, see who has changed what and much more.

In git you use a post-receive hook for this, and checkout the current branch to your working directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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