首页 > 解决方案 > rysnc 排除目录不起作用

问题描述

我有一个运行到 rsync 的脚本。我设置了 --exclude 但它忽略并同步这些文件夹。

set -x;
cd $(dir_name $0);
dest="/home/pi/bash_scripts_2/"
export RSYNC_RSH="ssh -q";

#excluding html and man folders
for dir in html man; do
   rsync -hav ./$dir/ --exclude 'html/' ./$dir/ $dest$dir/; 
   rsync -hav ./$dir/ --exclude 'man/' ./$dir/ $dest$dir/;
done

标签: bashshell

解决方案


您的循环正在做四件事。

第一个循环:

rsync html/ to dest/html excluding html/ (nothing copied)
rsync html/ to dest/html excluding man/ (html is copied to dest/html)

第二个循环:

rsync man/ to dest/man excluding html/ (man is copied to dest/man)
rsync man/ to dest/man excluding man/ (nothing copied)

所以总的来说,你正在复制这两个文件夹。


推荐阅读