Linux系统文件权限的备份与恢复

最近一直在思考一个问题,若是手抖不当心执行命令chmod 777 -R /,恰好没有系统备份,那就真的是悲剧了。生产系统的备份,真的是重中之重啊。bash

本次只讨论如何备份系统文件权限。ide

一、建立一个文件,用于测试。测试

[root@reed ~]# ll testfacl.txt 
-rw-r--r-- 1 root root 0 Mar 16 05:27 testfacl.txt

能够看出testfacl.txt文件权限为644。rest

二、备份当前目录下(包括子目录)全部文件的权限get

[root@reed ~]# getfacl -R . >/tmp/facl.bak
[root@reed ~]# grep "testfacl.txt" -A 5 /tmp/facl.bak  
# file: testfacl.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--

三、修改文件权限it

[root@reed ~]# chmod 777 testfacl.txt ;ll testfacl.txt 
-rwxrwxrwx 1 root root 0 Mar 16 05:27 testfacl.txt

四、恢复文件权限class

[root@reed ~]# setfacl --restore=/tmp/facl.bak 
[root@reed ~]# ll testfacl.txt 
-rw-r--r-- 1 root root 0 Mar 16 05:27 testfacl.txt

能够看出,已经恢复以前备份的权限了。test

防患于未然,最好给每一个系统作一个文件权限备份,要否则省得欲哭无泪。file

getfacl -R / >/tmp/a.facl
相关文章
相关标签/搜索