Rsync how to include directories but not files?

chicama picture chicama · Aug 23, 2010 · Viewed 27.5k times · Source

I have a directory structure and files like this

data/
data/a.txt
data/folder/
data/folder/b.txt
data/folder/folder/
data/folder/folder/c.txt
...

a.txt, b.txt, and c.txt are large files that are computer-generated and renewed frequently. They should NOT be backuped -- but I want to backup the directory structure :

data/
data/folder/
data/folder/folder/

How can I do this with rsync and --exclude-from, without specifying every folder, but something like rsync -a data/* --exclude-from=exclude.rsync "" --onlyfoldersandnotfiles""?

Thanks for help !

Answer

luison picture luison · Feb 11, 2012
$ rsync -a -f"+ */" -f"- *" source/ destination/

"The two -f arguments mean, respectively, "copy all directories" and then "do not copy anything else"."

Further details: http://psung.blogspot.com/2008/05/copying-directory-trees-with-rsync.html