Rsync how to include directories but not files?

自闭症网瘾萝莉.ら 提交于 2020-01-22 02:07:50

问题


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 !


回答1:


$ 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




回答2:


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

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




回答3:


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.



来源:https://stackoverflow.com/questions/59726175/how-to-copy-a-full-directory-structure-in-unix-with-symbolic-links-without-any

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!