rysnc排除目录无效

时间:2018-06-08 11:44:29

标签: bash shell

我有一个运行到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

3 个答案:

答案 0 :(得分:0)

你的循环正在做四件事。

第一循环:

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)

总的来说,你要复制这两个文件夹。

答案 1 :(得分:0)

如果你不想复制它们,你不应该通过 <{strong> htmlman作为参数。

考虑以下测试设置:

mkdir -p src{/html,/man,/do-copy-me} dest
touch src/copy-me src/{html,man}/dont-copy-me src/do-copy-me/yes-really

......鉴于此,这有效:

rsync -hav --exclude=html --exclude=man src/. dest/.

请注意,我们不会将htmlman作为显式参数传递,而是包含它们的父目录。

您会发现dest正确包含do-copy-me/yes-reallydo-copy-me,但不包含htmlman

答案 2 :(得分:0)

我认为我所要做的就是从/删除html/。使用.因为我对当前目录执行了cd。仍然需要硬编码dest目录。但这似乎有效。将尝试使用--exclude-from 'filename.txt'来清理代码。感谢您的帮助。

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

for dir in html man whatever; do
   rsync -hav --exclude 'html' --exclude 'man' --exclude 'whatever' . $dest;
done