Use the following command:
rsync -av --include-from=DirectoriesToCopy.txt --include /data/ --exclude='/data/*' --exclude='/*/' / /media/MyDestination/
You need to include /data/ explicitly, you could also have added that to the list in the file. Then exclude all other directories (order is important with includes/excludes).
Note that your usage of -r
was redundant as that's included in -a
.
EDIT:
You could also accomplish the same result with:
rsync -av --relative /data/Dir1 /data/Dir2 /media/MyDestination/
It's not rsync that's forcing you to do difficult things just to copy a couple of directories, it just gives you multiple ways of doing the same thing; in some cases going the include/exclude way may be more suited, here I'd do the --relative thing above (without --relative
you'd end up with /media/MyDestination/Dir1
and /media/MyDestination/Dir2
, with the --relative
the whole source path is copied to the destination).
/data/Dir1
and/data/Dir2
including their contents to/media/MyDestination/Dir1
and/media/MyDestination/Dir2
? Or do you want to include the/data
part? How large is this list, is it too big to simply list those entries on the command line? Anyway, your--exclude
statements prevent the recursion./media/MyDestination/data/Dir2/
. I added the --exclude to prevent other directories and files in / from getting copied.rsync -av $(cat DirectotiesToCopy.txt) /media/MyDestination/