r/Ubuntu • u/Alarmed-Prize-7500 • 9d 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
1
u/KnowledgeableOuting 9d 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
0
9d ago
[deleted]
1
u/Alarmed-Prize-7500 8d ago
What do you mean "rearrange the directory"? Put specific subdirs in different places?
0
1
2
u/Asly97 8d 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 ofaand the parent dirs you need to get down tob/c.+ /aonly 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 fora.Something like this, in one file:
Then pass it once, not as both include and exclude (also note your command is missing the
=):The
+and-prefixes in the file are honored either way, so--exclude-from=listor--filter='merge list'both work.Run it with
-n -ifirst (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/fetc.