9

When syncing my remote backup I get the error rsync cannot delete non-empty directory.

I know the cause: I have excluded some files and when rsync tries to delete a remote directory because it doesn't exists locally, it can't since it is not empty. Without the exclusion the directory would be emptied.

I also know I could get rid of the problem by using --delete-excluded, but that is not want I want.

I would like to skip uploading certain files (because they are too big for my upload speed), but I want to keep those I have already uploaded some time ago if they exist locally. If they do not exist locally, they should be deleted. --delete-excluded would delete them all on the remote side.

That also means that if a directory doesn't exists anymore locally, it should be deleted even if it contains excluded files.

Is it possible to setup rsync to accomplish this?

4

Use the p modifier:

A p indicates that a rule is perishable, meaning that it is ignored in directories that are being deleted. For instance, the -C option’s default rules that exclude things like "CVS" and "*.o" are marked as perishable, and will not prevent a directory that was removed on the source from being deleted on the destination.

For example, I use the -F option, which "tells rsync to look for per-directory .rsync-filter files that have been sprinkled through the hierarchy and use their rules to filter the files in the transfer."

My .rsync-filter contains lines like these to filter out these "droppings" that Macs leave behind them:

-p .DS_Store
-p ._*

If using exclude instead of just -, add a comma. For example :

exclude,p .DS_Store
exclude,p Thumbs.db
0

You can use modifiers of include/exclude pattern, add -s on the pattern you used. It tell rsync that exclude rule only for send-side.

-n : only check what will delete on desc, don't delete pattern: *.sh desc: /home/kg/tmp

aim: want to delete file end of .sh on desc, but if you do this, you can't delete on the desc: rsync -rvz --exclude *.sh --delete -n conkg kg@192.168.31.202:/home/kg/tmp

should change to : please add -n when you test test: rsync -rvz --exclude-from del.txt -n --delete conkg kg@192.168.31.202:/home/kg/tmp real delete: rsync -rvz --exclude-from del.txt --delete conkg kg@192.168.31.202:/home/kg/tmp cat del.txt -s*.sh

or: rsync -rvz --exclude -s*.sh --delete conkg kg@192.168.31.202:/home/kg/tmp

-2

just use the '--max-size=xx' and '--delete' options of rsync. It will do everything automatically and meet all your requirements.

  • It would at most be a workaround. I want to skip mov, avi and cr2 files completely because they generally are very large. But those I have already uploaded on a faster line some time ago should be kept. Now the problem is that the largest JPG files are bigger than the smallest CR2 files, so this solution is not ideal. I would rather use the exclude feature to filter on filenames. – marlar Jan 30 '13 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.