防止rsync删除排除的目录

我通过Ansible的同步模块使用rsync和以下任务定义:

synchronize: src='{{ local_app_path }}/.' dest='{{ remote_app_path }}/' perms=no owner=yes rsync_opts=--delete-after 

运行此任务将生成以下命令:

 rsync --delay-updates -FF --compress --archive --no-perms --rsh 'ssh -S none -o StrictHostKeyChecking=no' --rsync-path="sudo rsync" --delete-after --out-format='<<CHANGED>>%i %n%L' "../src/." "[email protected]:/var/www/app/" 

我的目录布局是这样的:

 src/ # ... app/ test/ node_modules/ package.json provisioning/ # ... playbook.yml .rsync-filter 

这是我的.rsyncfilter:

 exclude /src/.env exclude /src/node_modules 

现在我期望运行我的同步任务,并在服务器上得到的目录结构如下所示(注意缺less的node_modules文件夹):

 app/ test/ package.json 

这工作。 但是,一旦我在服务器上创build一个node_modules文件夹…

 app/ test/ node_modules/ package.json 

…并再次运行同步, node_modules夹再次从服务器上删除(即使我已经排除在我的.rsyncfilter):

 app/ test/ package.json 

我期望node_modules夹保存在服务器上,因为我已经在我的.rsync-filter列出了它,而不是使用--delete-excluded选项。

如何防止使用rsync删除排除的文件/目录?

非常感谢你的帮助! 🙂

这是导致你的问题的-FF 。 这会停止正在复制的-rsync-filter文件,正如rsync手册页所述…

 MERGE-FILE FILTER RULES ... These per-directory rule files must be created on the sending side because it is the sending side that is being scanned for the available files to transfer. These rule files may also need to be transferred to the receiving side if you want them to affect what files don't get deleted (see PER-DIRECTORY RULES AND DELETE below). 

重要的是这个引用部分的最后一句。 改变-FF-F给出所需的行为。