How to use Rsync to copy only specific subdirectories (same names in several directories)

后端 未结 4 1568
情话喂你
情话喂你 2021-01-31 08:36

I have such directories structure on server 1:

  • data
    • company1
      • unique_folder1
      • other_folder
      • ...
    • company2
4条回答
  •  野性不改
    2021-01-31 09:09

    An alternative to Andron's Answer which is simpler to both understand and implement in many cases is to use the --files-from=FILE option. For the current problem,

    rsync -arv --files-from='list.txt' old_path/data new_path/data
    

    Where list.txt is simply

    company1/unique_folder1/
    company2/unique_folder1/
    ...
    

    Note the -r flag must be included explicitly since --files-from turns off this behaviour of the -a flag. It also seems to me that the path construction is different from other rsync commands, in that company1/unique_folder1/ matches but /data/company1/unique_folder1/ does not.

提交回复
热议问题