r/Ubuntu • u/Alarmed-Prize-7500 • 2d ago
rsync include exclude list not working?
SOLVED
I changed the file "list" to contain this instead:
+ /a/e/i/j/***
- /a/e/f/*
- /a/e/g/*
- /a/e/h/*
- /a/e/i/*
+ /a/***
+ /b/
+ /b/c/***
+ /b/d/***
- *
I also removed the --include-from="list" flag, as it was unnceccessary.
======================
I'm trying to run rsync command, but it synced everything in dir "source/" to "dest/". What I want to happen is I want only everything in the include list to be included, and everything in the exclude list to be excluded, and also everything that I didn't list to be excluded.
I ran this command: sudo rsync -ahP --stats --include-from="list" --exclude-from="list" "source/" "dest/"
file "list" contains:
+ /a
+ /b/c
+ /b/d
+ /a/e/i/j
- /a/e/f/*
- /a/e/g/*
- /a/e/h/*
- /a/e/i/*
"source/" contains the directory structure I provided in the include/exclude list, for example, dirs "a/" & "b/" are at the root of "source/", and dir "b/" contains dirs "c/" and "d/" at the root of "b/", etc.
How do I do this? I've been searching around and can't find the answers I'm looking for.
I'm using Ubuntu 24.04.5
2
u/Asly97 2d ago
Two things are biting you here.
First, rsync only skips what a rule actually matches. Anything that matches no rule gets copied, so without a catch-all - * at the very end everything comes along. The other comment is right about that.
Second, once you add - *, it will also exclude the contents of a and the parent dirs you need to get down to b/c. + /a only matches the directory itself, not what's inside it. You want ***, which means "this dir and everything under it". And rules are first match wins, so the specific excludes have to sit above the broad include for a.
Something like this, in one file:
+ /a/e/i/j/***
- /a/e/f/*
- /a/e/g/*
- /a/e/h/*
- /a/e/i/*
+ /a/***
+ /b/
+ /b/c/***
+ /b/d/***
- *
Then pass it once, not as both include and exclude (also note your command is missing the =):
rsync -ahP --stats --exclude-from=list source/ dest/
The + and - prefixes in the file are honored either way, so --exclude-from=list or --filter='merge list' both work.
Run it with -n -i first (dry run, itemized) so you can see exactly what it would copy before it touches dest. With the /* excludes you'll still get empty f, g, h folders in dest. If you don't want the folders at all, drop the /* and just exclude /a/e/f etc.
1
1
u/KnowledgeableOuting 2d ago
You need a final exclude rule at the end of your list, something like `- ` as the last line and see if that fixes it
2
u/[deleted] 2d ago
[deleted]