rsync 'cannot delete non-empty directory' errors, even with --force option

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/"