Ubuntu 16.04 rsync – doing backups of the NAS server, can I tell it to exclude all the .Trash directories

backupnasrsyncUbuntu

I use my NAS to back up several smaller systems that monitor the solar plant, using rsync. It works great. Now I want to back up the entire NAS drive.

There are subdirectories for each linux machine – 8 of them.

As I have learned more and tuned my exclusions I see a whole lot of leftovers that I forgot to exclude earlier.

In the past I excluded the /lost+found directories but didn't think about /.trash-1000 and now there are a lot of them.

Simply adding them to the --exclude list, even with --delete doesn't delete them because exclude makes the rsync program skip them entirely.

It does not operate the same way Robocopy /MIR does.

So let's start with .Trash and I think the answer will help me if I find others that I originally forgot to exclude.

Obviously, one solution is to delete the entire directory for each server in turn and then re-run a full rsync with the new set of exclusions.

But that is a lot of work, to say the least.

So my question is, when I make a full rsync of the NAS drive, is there a generic way to exclude all .Trash-1000 folders? If this works, I may swap the drives and resume operations with the cleaner one.

I'm looking for something like this:

--exclude="*.Trash*"

…so it would not copy them, regardless of their location in the directory structure.


I really want to know how to do this with rsync, and am looking for a solution to the problem of how adding excludes causes rsync to skip them rather than deleting them.

Alternatively, instead of doing it during the rsyncs, I would welcome an answer that would show me how to seek and destroy these directories on the original NAS drive.

rsync – How to make it delete directories or files recently added to the exclusions list

Best Answer

Here are some Q&A's that talk to the alternative:

How to delete directories based on find output?

How to remove folders with a certain name

find + delete files that contain “.”

And between them I believe my best option for the immediate problem is to remove them from the original drive by executing this in the directory that contains the full backups of the other systems:

cd /mnt/full
sudo rm -rf `sudo find -type d -name '.Trash-1000'`

Search and destroy, hoo-rah!

It worked and will make future rsync work faster in the future.


This does not solve the rsync bug, though.


If anybody has an answer that will make rsync delete directories that I later add to the --exclude list, then that would be the answer I will gladly accept.

Related Question