繁体   English   中英

如何排除`.git`然后备份和恢复文件夹和文件的所有者和权限?

[英]How to exclude `.git` then backup and restore folders and files owner and permission?

我更喜欢使用 bash 脚本,因为getfacl,setfacl有大问题(bug)。

在问这个问题之前,我还搜索了一种纯bash脚本的方法来备份和恢复owner and permission可惜没有人承认完美的答案。

然后我使用一种简单的方法来备份和恢复所有者和权限:

getfacl -R . >permissions.facl
setfacl --restore=permissions.facl

如果我要排除.git. ,怎么做?

是的你可以。

例如,我的目录看起来像

[root@967dd7743677 test]# ls -la
total 20
drwxr-xr-x 4 root root 4096 Jan 11 06:37 .
drwxr-xr-x 1 root root 4096 Jan  2 11:08 ..
drwxr-xr-x 8 root root 4096 Jan  2 12:56 .git
drwxr-xr-x 2 root root 4096 Jan 11 06:37 1one
-rw-r--r-- 1 root root   19 Jan  2 12:55 testfile
[root@967dd7743677 test]#

通过使用find你可以排除任何你想要的目录

find . -type f -not -path '*/\.git/*' -exec getfacl -R {} \;

所以通过-exec我们调用getfacl -R

你可以重定向输出

find . -type f -not -path '*/\.git/*' -exec getfacl -R {} \; > permissions.facl

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM