The meaning of life is to explore the world

rsync usage

Posted on By Jason Liu

  1. rsync Linux man page:
    https://linux.die.net/man/1/rsync

  2. rsync -navur “sourceDir/” “targetDir”.
    -n: dry run
    -a: archive
    -v: verbose
    -u: newer
    -r: recursion

  3. rsync filter rules only apply to the first match.
    # "test" will be included:
    rsync -av --include="test" --exclude="test" "source" "target"
    
  4. rsync filter rules do not consider directories in source or target.
    # "subDir" will not be matched or filtered out:
    rsync -av --exclude="subDir" "source/subDir/" "target/subDir"
    
  5. rsync filter rules for include pattern only work step by step.
    # Without the first two include, the 3rd one won't match anything
    rsync -navur --include='Melanie/' --include='Melanie/temp/' --include='Melanie/temp/**' --exclude='*' "/mnt/d/" "/mnt/e"
    
  6. rsync filter rule patterns does not expand * with /, only ** expands /.
    # source/dir1/dir2/dir3 won't be excluded
    rsync -avr --exclude="dir1/*" "source/" "target"
    # source/dir1/dir2/dir3 will be excluded
    rsync -avr --exclude="dir3/**" "source/" "target"