linux - 如何克隆ACL权限?

标签 linux bash permissions acl

我刚刚发现我的备份缺少 ACL,并且在修复之前无法恢复。

幸运的是,我有幸检查权限在正在运行的系统上应该是什么样子,例如:

恢复:

# file: samba/sysvol
# owner: root
# group: 3000000
user::rwx
group::rwx
other::---

正在运行:

# file: samba/sysvol
# owner: root
# group: 3000000
user::rwx
user:root:rwx
group::rwx
group:3000000:rwx
group:3000001:r-x
group:3000002:rwx
group:3000003:r-x
mask::rwx
other::---
default:user::rwx
default:user:root:rwx
default:group::---
default:group:3000000:rwx
default:group:3000001:r-x
default:group:3000002:rwx
default:group:3000003:r-x
default:mask::rwx
default:other::---

没有简单的权限模式可以遵循,因此手动协调将花费很长时间并且容易出错。

问题:

是否可以“克隆”ACL 权限?

即递归读取所有文件和文件夹的 ACL(getfacl?)并写入(setacl?)到其他地方的相同文件和文件夹列表?

最佳答案

如果源和目标都在本地,或者您可以通过 SSH 或 rsync 协议(protocol)在它们之间进行复制,则可以使用 rsync -A 在目录之间复制 ACL。

这将在同一台机器上本地复制 ACL。

rsync -Ar dir1/ dir2/

如果两台服务器都有兼容的 ACL,您可以使用它通过网络复制 ACL,而无需实际再次复制文件。

rsync -Ar /dir1/ user@destination:/dir2/

rsync -Ar user@source:/dir1/ /dir2/

取决于您正在运行命令的服务器。

来自 rsync 手册页:

-A, --acls This option causes rsync to update the destination ACLs to be the same as the source ACLs. The option also implies --perms.

The source and destination systems must have compatible ACL entries for this option to work properly. See the --fake-super option for a way to backup and restore ACLs that are not compatible.

关于linux - 如何克隆ACL权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57162470/

相关文章:

linux - 如何读/写 hci_le_create_conn 返回的句柄?

bash - 使用 vanilla Ubuntu,一个用于搜索和替换/取消注释代码块的脚本?

linux - 权限设置为644但用户无法读取:-(

permissions - 如何在 Orchard CMS 中设置博客的权限?

android - 应用程序如何在 Lollipop 上使用系统权限

python - 如何在 EC2 linux 环境中降级我的 BeautifulSoup 版本?

java - 在 Debian Linux 上安装 Oracle SQL Developer 时出现问题

linux - 如何在 bash 脚本根模式下获取用户的 $HOME 目录?

linux - SED:显示前 10 行复杂的表达式

linux - Bash Script 添加、删除、用户、目录和文件