Introduction to Linux backup and recovery and file permissions

Y2J
Release: 2017-05-24 14:28:09
Original
2547 people have browsed it

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

On CentOS, Fedora, 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 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--
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 original permissions

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

  2. 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]$
Copy after login
[Related recommendations]

1.

Mysql Free video tutorial

2.

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!