你可能聽說或碰到過這樣的事情:乙個系統管理員菜鳥不小心輸入"chmod -r 777 /"從而導致了巨大的悲劇,使得整個系統遭到了嚴重的破壞。在日常管理中,我們有許多任務具可以用來備份檔案許可權,如cp、rsync、etckeeper等。如果你使用了這個備份工具,那麼你的確不需要擔心改變的檔案許可權問題。
但如果只是想暫時備份檔案許可權(而不是檔案本身),例如:為了阻止一些目錄的內容被覆蓋暫時移除該目錄下所有檔案寫的許可權;或是正在排除檔案許可權問題的過程中需要對檔案進行chmod命令操作。在這些情況下,我們可以在原始檔案許可權改變之前對其進行備份,一會我們需要它的時候再將原始許可權還原。在很多情況下,如果你只是想要備份檔案的許可權,那麼完整的檔案備份是不必要的。
在linux上,實際上備份和恢復檔案許可權使用訪問控制列表(acl)是容易的。acl根據不同的屬主和屬組在相容posix的檔案系統上定義了單個檔案的許可權。
以下演示如何使用acl工具備份和恢復linux的檔案許可權
在debian, ubuntu,linux mint上
$
sudo
apt-get
install acl
在centos,fedora,rhel上
$
sudo
yuminstall acl
[
root@linuxprobe tmp
]#ls
-l
total
8-
rwxr--r
--.1
root root
0mar304
:40install
.txt
-
rwxr-xr
-x.1
root root
0mar304
:41linuxprobe
.txt
[
root@linuxprobe tmp
]#getfacl -r
.>
permissions
.txt
...
此命令將所有檔案的acl資訊全部寫入名為permissions.txt檔案。
以下是生成的permissions.txt檔案中部分目錄資訊
[
root@linuxprobe tmp
]#cat
permissions
.txt
#
file
:.#
owner
:root
#
group
:root
#
flags:--
tuser
::rwx
group
::rwx
other
::rwx
#
file
:install
.txt
#
owner
:root
#
group
:root
user
::rwx
group::r
--other::r
--#
file
:linuxprobe
.txt
#
owner
:root
#
group
:root
user
::rwx
group::r
-xother::r
-x#
file
:permissions
.txt
#
owner
:root
#
group
:root
user
::rw
-group::r
--other::r
--...
[
root@linuxprobe tmp
]#chmod
733linuxprobe
.txt
[
root@linuxprobe tmp
]#chmod
573install
.txt
[
root@linuxprobe tmp
]#ls
-ltotal
8-r-
xrwx-wx
.1root root
0mar304
:40install
.txt
-
rwx-wx-
wx.1root root
0mar304
:41linuxprobe
.txt
-rw-
r--r--.
1root root
4361
mar304:
41permissions
.txt
......
1)cd到建立permissions.txt時所在的目錄
2)執行以下命令:
setfacl
--restore
=permissions
.txt
可以看到linuxprobe.txt及install.txt許可權恢復了
[
root@linuxprobe tmp
]#setfacl
--restore
=permissions
.txt
[
root@linuxprobe tmp
]#ls
-ltotal
8-
rwxr--r
--.1
root root
0mar304
:40install
.txt
-
rwxr-xr
-x.1
root root
0mar304
:41linuxprobe
.txt
-rw-
r--r--.
1root root
4361
mar304:
41permissions
.txt
......
原文發布時間為:2013-04-02.
詳解如何備份及恢復 Linux 檔案許可權
你可能聽說或碰到過這樣的事情 乙個系統管理員菜鳥不小心輸入 chmod r 777 從而導致了巨大的悲劇,使得整個系統遭到了嚴重的破壞。在日常管理中,我們有許多任務具可以用來備份檔案許可權,如cp rsync etckee程式設計客棧per等。如果你使用了這個備份工具,那麼你的確不需要擔心改變的檔案...
Linux備份及恢復及Linux檔案許可權詳解
linux備份及恢復及linux檔案許可權詳解 概述乙個系統管理員菜鳥不小心輸入 chmod r 777 從而導致了巨大的悲劇,使得整個系統遭到了嚴重的破壞。在日常管理中,我們有許多任務具可以用來備份檔案許可權,如cp rsync etckeeper等。如果你使用了這個備份工具,那麼你的確不需要擔心...
Linux 備份及恢復 Linux 檔案許可權
乙個系統管理員菜鳥不小心輸入 chmod r 777 從而導致了巨大的悲劇,使得整個系統遭到了嚴重的破壞。在日常管理中,我們有許多任務具可以用來備份檔案許可權,如cp rsync etckeeper等。如果你使用了這個備份工具,那麼你的確不需要擔心改變的檔案許可權問題。但如果只是想暫時備份檔案許可權...