Detailed explanation of Linux backup and recovery and Linux file permissions

黄舟
Release: 2017-06-04 11:28:10
Original
1456 people have browsed it

This article mainly introduces Linux backup and recovery and detailed explanation of Linux file permissions. Friends in need can refer to

Linux backup and recovery and Linux files. Detailed explanation of permissions

Overview

A system administrator rookie accidentally entered "chmod -R 777 /", which resulted in a huge The tragedy caused serious damage to the entire system. 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 permission 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.

##Install ACL Tool

On Debian, Ubuntu, Linux Mint

$ sudo apt-get install acl
Copy after login

On CentOS, Fedora, On RHEL

$ sudo yum install acl
Copy after login

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
Copy after login

This command will write all the ACL information of all files named permissions. txt file.

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--
Copy after login

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
Copy after login

Restore the original permissions

  1. cd to the directory where sys_info.sh was created

  2. Execute the following command:

  3. [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]$
    Copy after login

    The above is the detailed content of Detailed explanation of Linux backup and recovery and Linux file permissions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template