提问人:Justin Spencer 提问时间:12/28/2016 更新时间:4/3/2023 访问量:6072
rsync --exclude-from 'list' 文件不起作用
rsync --exclude-from 'list' file not working
问:
我正在尝试使用 rsync 完成从远程服务器到本地计算机的未完成传输
rsync -a [email protected]:~/source/ /dest/
其中 是部分完成的传输的位置。但是,由于带宽问题,我需要在没有副本的另一台机器上运行 rsync,然后我可以从那里移动到/dest/
/tmp_dest/
/dest/
/tmp_dest/
/dest/
到目前为止,我想出的解决方案是使用 rync 的选项,使用包含来自 .--exclude-from
/dest/
该命令如下所示
rsync -a --exclude-from 'list.txt' [email protected]:~/source/ /tmp_dest/
在这一点上,我觉得我已经到处寻找解决方案,并尝试了我遇到的每一个变体。
这包括'list.txt'
相对:
path 1/file 1
path 2/file 2
--或--
绝对:
/absolute/source/path 1/file 1
/absolute/source/path 2/file 2
我已经尝试了上述组合,包括明确排除该行(我在那里看到了人们也想要其他文件的示例)-
+
- /absolute/source/path 1/file 1
- /absolute/source/path 2/file 2
我尝试将前导放在文件路径的前面以纠正相对路径问题**/
**/path 1/file 1
**/path 2/file 2
我还尝试导航到包含 rsync 的目录并从那里执行 rsync,以避免 rsync 查找的问题'list'
/path/to/the/list/something1/to.exclude
/path/to/the/list/something2/to.exclude
/path/to/the/list/something3/to.exclude
毫无疑问,什么也没找到
我还确保在“列表”文件中使用了正确的换行符。即 (Unix) 换行符。LF
我尝试使用以下命令创建'list'
find . -type f | tee list.txt
这最初创建了一个看起来像这样的文件
./yyyy-mm-dd folder 1/sub folder [foo]/file.a
./(yyyy) folder 2 {foo2}/file.b
./folder, 3/sub-folder 3/file.c
如您所见,文件路径中有空格和其他字符,但根据我目前的理解,这应该不会影响。但也许我弄错了,需要转义任何具有特殊含义的字符,然后我可能需要帮助
然后,我在记事本++或其他一些文本编辑器中执行替换,该编辑器保留(Unix)换行符以获得所需的结果。
(例如,如上所述,我尝试用无替换,注意前导斜杠,甚至双通配符以匹配包含文件的任何父树结构。./
LF
./
/absolute/path/for/source/
我觉得我唯一没有尝试过的是转义文件名和路径中的空格,但我已经读到这应该不是问题。
也许我忽略了一些东西,任何帮助将不胜感激。
答:
以下是 rsync 手册页如何使用 “--exclude-from”: --exclude-from=FILE 读取从 FILE 中排除模式
使用以下命令: rsync -a --exclude-from=list.txt [email protected]:~/source/ /tmp_dest/
而且最好使用列表.txt文件的完整路径名
评论
rsync -anv --exclude-from=/home/rsync.exclude /source/ /empty_dir/
rsync -anv --exclude-from '/home/rsync.exclude' /source/ /empty_dir/
相对于源目录的路径应该有效。 例如:
rsync -ar test1/ test2/ --exclude-from=list.txt
给定以下目录结构
test1
├── subdir
│ ├── subdir2
│ └── testF3.txt
├── testF1.txt
└── testF2.txt
排除文件:
testF2.*
subdir/subdir2/*
还可以使用 ** 来匹配任何子目录。
请确保路径中没有任何多余的空格(包括尾随空格),因为这些空格包含在模式中。
评论
list.txt
source/
./
-
**/
[
--exclude-from
[
--exclude-from
ls
sed
s/$/\//
[
s/\[/\\\[/g
ls /source/ | sed 's/$/\//;s/\[/\\\[/g' | tee /home/rsync.exclude
rsync -anv --exclude-from=/home/rsync.exclude /source/ /empty_dir/ | tee /home/rsync.output
foo.../
...bar/