rsync 'cannot delete non-empty directory' errors, even with --force option
When running this command:
$ sudo rsync -r --delete --force --checksum --exclude=uploads /data/prep/* /data/app/
I'm getting the following output:
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
From reading the man rsync
it was my impression that the --force
option would tell rsync to delete these non-empty directories, which is the desired result.
Ref:
--force force deletion of dirs even if not empty
How can I modify the command to delete the non-empty directories?
I'm using rsync version 3.0.8, on Gentoo Base System release 2.0.3, in case that's relevant.
Update: Added sudo
to the command to make it clear that this is not a file permissions issue.
Solution 1:
Did you try to add --delete-excluded
?
If you delete a directory in your excluded folders on the "remote" side, rsync --delete
will not delete the excluded folder on your "local" site.
Solution 2:
Here are possible sources of this problem:
(1) This error can be the result of the -b (--backup) option. This option will create a backup of each deleted file, by appending a tilde (~) on its file name. (This confused me, as the file-name is clearly a backup, but the directory name is not, as you can't see the tilde.)
To check if this is the same case, read your target directory on the deepest level, and check if there is any tilde (~) ending file. Note that these tilde-appended-files-names are then invisible in some common file browsing system, so you may not see them.
To solve this case, prefer the --backup-dir=DIR option, for instance --backup-dir=.rsync_bak.
(2) The --exclude option can have the same results. Which is possibly happening in your case. The pattern system is powerful, but may be misleading. For instance if you write --exclude='*~', this will skip all tilde ending files, resulting exactly like in case (1) above.
from rsync man page:
if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname
Si if you write --exclude=uploads, this will exclude all files named "updloads", at any level of your files tree.
Check if there is a file named "uploads" inside your unable-to-delete directories.
Solution would be to change "--exclude=uploads" to "--exclude=uploads/"