This article mainly introduces relevant information about Linux backup and recovery and detailed explanation of Linux file permissions. Friends in need can refer to
Linux backup and recovery and detailed explanation of Linux file permissions
Overview
A system administrator rookie accidentally entered "chmod -R 777 /", which led to a huge tragedy and caused the entire system to suffer. To serious damage. In daily management, we have many tools that can be used to back up file permissions, such as cp, rsync, etckeeper, etc. If you use this backup tool, then you really don't need to worry about changing file permissions.
But if you just want to temporarily back up the file permissions (not the file itself), for example: to prevent the contents of some directories from being overwritten, temporarily remove the write permissions of all files in the directory; or you are troubleshooting file permissions problems During the process, you need to perform the chmod command on the file. In these cases, we can back up the original file permissions before they were changed and restore the original permissions later when we need it. In many cases, a full file backup is unnecessary if you just want to back up the file's permissions.
On Linux, it is actually easy to back up and restore file permissions using Access Control lists (ACLs). ACL defines the permissions of a single file on a POSIX-compatible file system based on different owners and groups.
Installing ACL Tools
On Debian, Ubuntu, Linux Mint
$ sudo apt-get install acl
On CentOS, Fedora, RHEL
$ sudo yum install acl
Back up the permissions of all files in the current directory (including subdirectories)
[xgj@entel2 shells]$ getfacl -R . > permissions.txt [xgj@entel2 shells]$ [xgj@entel2 shells]$ ll total 8 -rw-rw-r-- 1 xgj xgj 231 Jan 16 12:32 permissions.txt -rwxrwxr-x 1 xgj xgj 420 Jan 16 12:14 sys_info.sh
This command writes all ACL information of all files into a file named permissions.txt.
The following is some directory information in the generated permissions.txt file
[xgj@entel2 shells]$ cat permissions.txt # file: . # owner: xgj # group: xgj user::rwx group::rwx other::r-x # file: sys_info.sh # owner: xgj # group: xgj user::rwx group::rwx other::r-x # file: permissions.txt # owner: xgj # group: xgj user::rw- group::rw- other::r--
Modify the permissions of a certain file
[xgj@entel2 shells]$ ll total 8 -rw-rw-r-- 1 xgj xgj 231 Jan 16 12:32 permissions.txt -rwxrwxr-x 1 xgj xgj 420 Jan 16 12:14 sys_info.sh [xgj@entel2 shells]$ chmod 777 sys_info.sh [xgj@entel2 shells]$ ll total 8 -rw-rw-r-- 1 xgj xgj 231 Jan 16 12:32 permissions.txt -rwxrwxrwx 1 xgj xgj 420 Jan 16 12:14 sys_info.sh
Restore original permissions
cd to the directory where sys_info.sh was created
Execute the following command:
##
[xgj@entel2 shells]$ setfacl --restore=permissions.txt [xgj@entel2 shells]$ ll total 8 -rw-rw-r-- 1 xgj xgj 231 Jan 16 12:32 permissions.txt -rwxrwxr-x 1 xgj xgj 420 Jan 16 12:14 sys_info.sh [xgj@entel2 shells]$
Detailed explanation of innodb_index_stats when importing data Error prompting table primary key conflict
3.What should I do if garbled characters appear when decompressing zip files under Linux?
4.Teach you how to adjust the partition size in Linux
5.How to detect server network status in Linux
The above is the detailed content of Introduction to Linux backup and recovery and file permissions. For more information, please follow other related articles on the PHP Chinese website!