41

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 !

Manoj Govindan
  • 72,339
  • 21
  • 134
  • 141
chicama
  • 411
  • 1
  • 4
  • 4

4 Answers4

62
rsync -a --include='*/' --exclude='*' source/ destination/

Basically, first include all directories, then exclude all files.

Nikana Reklawyks
  • 3,233
  • 3
  • 33
  • 49
45
$ 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

luison
  • 1,850
  • 1
  • 19
  • 33
5
rsync -a -f"-! */" source/ destination/

Filter rule means "Exclude anything that's not a directory."

Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
GabrielA1
  • 51
  • 1
  • 1
-1

If you want to sync everything except one folder but you still want to keep the directory structure of that excluded folder, you should do the following:

$ rsync -a -f"+ /var/log/**/*/" -f"- /var/log/**/*" source/ destination/

See the exclude-list and the rsync command as an example.

ceremcem
  • 3,900
  • 4
  • 28
  • 66