0

Given two directories /.../src and /.../des,

  • they share some subdirectories share1 and share2
  • des also has a subdirectory named des1 which doesn't exist in src.

How can I perform file transfer from src to des (by rsync or other program you prefer), in order to

  • update share1 and share2 in des according to their samename directories in src, including

    • deleting all the files that are in des/share1 and des/share2 but not in src/share1 and src/share2,
    • adding all the files that are not in des/share1 and des/share2 but in src/share1 and src/share2, and
    • updating all the files that are in both des/share1 and src/share1 or in both des/share2 and src/share2,
  • keep des/des1 intact? Thanks.

0

1 Answer 1

1

There are two options. Both use rsync.

Either: Only update share1 and share2, deleting unknown files in the target

rsync --dry-run -avP --delete .../src/share1 .../src/share2 .../des/

Or: Update everything in des, deleting unknown files in the target except for des1

rsync --dry-run -avP --delete --exclude '/des1' .../src/ .../des/

When you're happy with the result, remove --dry-run.

9
  • Thanks. Does --exclude option apply to both source and destination?
    – Tim
    Commented Mar 10, 2015 at 19:07
  • @Tim, yes unless you override it with --delete-excluded. Commented Mar 10, 2015 at 19:26
  • In my example, can --delete in your command be replaced with --delete-excluded?
    – Tim
    Commented Mar 10, 2015 at 19:30
  • @Tim you really need to look at the man page for rsync. If you --delete-excluded you will delete excluded items. Commented Mar 10, 2015 at 19:46
  • Sorry, I meant to ask: can --exclude in your command be replaced with --delete-excluded? I think they are the same in my example?
    – Tim
    Commented Mar 10, 2015 at 19:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .