Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 简单RSync排除选项?_Linux_Rsync - Fatal编程技术网

Linux 简单RSync排除选项?

Linux 简单RSync排除选项?,linux,rsync,Linux,Rsync,我希望在我的rsync命令中有一个简单且有效的(多个)exclude选项。假设我将排除文件和目录: /var/www/html/test.txt /var/www/html/images/ 我所做的是: rsync-avz--exclude=“/var/www/html/test.txt”--exclude=“/var/www/html/images/”/var/www/htmlroot@xx.xx.xx.xx:/var/www 或 rsync-avz--exclude=/var/www/h

我希望在我的
rsync
命令中有一个简单且有效的(多个)
exclude
选项。假设我将排除
文件
目录

  • /var/www/html/test.txt
  • /var/www/html/images/
我所做的是:

rsync-avz--exclude=“/var/www/html/test.txt”--exclude=“/var/www/html/images/”/var/www/htmlroot@xx.xx.xx.xx:/var/www

rsync-avz--exclude=/var/www/html/test.txt--exclude=/var/www/html/images//var/www/htmlroot@xx.xx.xx.xx:/var/www

rsync-avz--exclude/var/www/html/test.txt--exclude/var/www/html/images//var/www/htmlroot@xx.xx.xx.xx:/var/www

但是,
--exclude
不起作用
一切都在进行中

  • 请用这种简单的格式怎么做

注意:我也不想使用外部排除列表文件。只要一个简单的命令就可以了。

经过多次学习和测试,我自己解决了这个问题。真正的问题是(对我来说)
--exclude
选项的使用格式是可以理解的

我不知道其他人在做什么,但我刚刚发现:

  • “--exclude”路径不能是完全绝对路径
因为我使用了如下路径:
--exclude/var/www/html/text.txt
,这导致了该操作不起作用。所以我过去喜欢:

--exclude text.txt --exclude images/

。。而且它有效

我个人喜欢
--exclude={text.txt,images/}
格式

  • 请记住,使用rsync时,所有以/开头的排除(或包括)路径都锚定到传输的根,在您的示例中,该根将是
    /var/www/html
    目录!!,因此,如果您指定
    /text.txt
    ,它将只是树中不在上面的传输目录的根目录下的文件。您可以找到更多信息和示例

只是一个警告:此命令将在文件层次结构中找到
text.txt
文件和
images
目录的任何位置(即,不只是在备份目录的顶层)排除这些文件和目录,这可能不是您想要的。我希望它能像这样工作,但这对我不起作用