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
相關文章
相關標籤/搜索