1

I am having a hard time figuring out exactly how to run rsync to get it to do what I need it to do. Basically what I need is as follows given a single source folder with multiple sub-directories:

-If files for a given subdirectory are changed in the source folder, sync those changes to the destination (update files and delete files not found in the source folder any longer).

-If a folder is found in the source but not the destination, sync the folder and all of its contents to the destination.

-If a folder is found in the destination but not in the source, do nothing (e.g. don't delete it).

This is what the directory structure would look like:

Source Folder
   Folder 1
      File 1 unchanged.txt
   Folder 2
      File 2 newer.txt
   Folder 3
      File 3.txt

Destination Folder
   Folder 1
      File 1 unchanged.txt
   Folder 2
      File 2 old.txt (to be replaced with File 2 newer.txt)
   (Folder 3 not yet in destination, to be added from source)
   Folder X (not in source, to be left untouched)
0

According to man rsync you can use:

--exclude=PATTERN

Or your list is too large you can use :

--exclude-from=FILE 
  • This has nothing to do with the question. – Gilles Oct 28 '14 at 23:46
0

What you describe is the default standard behavior for rsync.

If you wanted a different behavior you would have to use one of the --delete options.

This is a test that proves my point:

 $ mkdir tmp1
 $ mkdir tmp2
 $ mkdir tmp1/1
 $ mkdir tmp1/2
 $ mkdir tmp2/1
 $ mkdir tmp2/X
 $ touch tmp1/1/1.txt
 $ touch tmp1/2/2.txt
 $ rsync -avz tmp1 tmp2
 sending incremental file list
 tmp1/
 tmp1/1/
 tmp1/1/1.txt
 tmp1/2/
 tmp1/2/2.txt

 sent 208 bytes  received 62 bytes  540.00 bytes/sec
 total size is 0  speedup is 0.00
 $ ls tmp2
 1  tmp1  X

You can see that directory X is there, untouched.

If you are using it as a daemon, maybe your rsync is applying options from a config file.

Look at /etc/rsyncd.conf to see if any delete options are set there or at rsyncd.conf at the home directory of the user that is launching the rsync

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.