rsync “无法删除非空目录”错误,即使使用 --force 选项

tom*_*all 31 rsync gentoo man deleting

运行此命令时:

$ sudo rsync -r --delete --force --checksum --exclude=uploads /data/prep/* /data/app/
Run Code Online (Sandbox Code Playgroud)

我得到以下输出:

cannot delete non-empty directory: html/js/ckeditor/_source/plugins/uicolor/yui
cannot delete non-empty directory: html/js/ckeditor/_source/plugins/uicolor/yui
cannot delete non-empty directory: html/js/ckeditor/_source/plugins/uicolor
cannot delete non-empty directory: html/js/ckeditor/_source/plugins/uicolor
cannot delete non-empty directory: html/js/ckeditor/_source/plugins
cannot delete non-empty directory: html/js/ckeditor/_source/plugins
cannot delete non-empty directory: html/js/ckeditor/_source
cannot delete non-empty directory: html/js/ckeditor/_samples
cannot delete non-empty directory: html/js/ckeditor/plugins/uicolor/yui
cannot delete non-empty directory: html/js/ckeditor/plugins/uicolor/yui
cannot delete non-empty directory: html/js/ckeditor/plugins/uicolor
Run Code Online (Sandbox Code Playgroud)

通过阅读man rsync我的印象,该--force选项会告诉 rsync 删除这些非空目录,这是预期的结果。

参考:

--force                 force deletion of dirs even if not empty
Run Code Online (Sandbox Code Playgroud)

如何修改命令以删除非空目录?

我在 Gentoo Base System 2.0.3 版上使用 rsync 3.0.8 版,以防万一。

更新:添加sudo到命令中以明确这不是文件权限问题。

Mar*_*ger 45

您是否尝试添加--delete-excluded

如果您在“远程”端rsync --delete删除排除文件夹中的目录,则不会删除“本地”站点上的排除文件夹。


小智 8

以下是此问题的可能来源:

(1)此错误可能是-b (--backup) 选项的结果。此选项将通过在其文件名上附加波浪号 ( ~ )来创建每个已删除文件的备份。(这让我很困惑,因为文件名显然是备份,但目录名不是,因为您看不到波浪号。)

要检查这是否相同,请在最深层读取目标目录,并检查是否有波浪号 (~) 结尾文件。请注意,这些波浪号附加文件名在某些常见的文件浏览系统中是不可见的,因此您可能看不到它们。

要解决这种情况,请首选 --backup-dir=DIR 选项,例如 --backup-dir=.rsync_bak。

(2) --exclude 选项可以有相同的结果。在您的情况下可能会发生这种情况。模式系统很强大,但可能会产生误导。例如,如果你写--exclude='*~',这将跳过所有波浪号结尾的文件,结果与上面的情况(1)完全一样。

来自 rsync 手册页:

如果模式以 / 开头,则它被锚定到文件层次结构中的特定位置,否则它与路径名的末尾匹配

如果你写--exclude=uploads,这将排除所有名为“updloads”的文件,在你的文件树的任何级别。

检查无法删除的目录中是否有名为“uploads”的文件。

解决方案是将“--exclude=uploads”更改为“--exclude=uploads/”