How to back up and restore Linux file permissions

  

During the use of Linux systems, sometimes we will use some tools to backup or restore file permissions for daily file management. In fact, it is not difficult to use the access control list for backup and restore file permissions. The ACL defines the permissions of a single file on a posix-compatible file system based on different owners and groups. The following small series will introduce you to the method of backing up and restoring Linux file permissions.

The following demonstrates how to use the tool to back up and restore Linux ACL file permissions

1. Installation ACL tool

on
in Debian, Ubuntu, Linux Mint

$ sudo apt-get install acl

on CentOS, Fedora, RHEL

$ sudo yum install acl

2. Back up the current directory (including subdirectories) Permissions for all files

[root@linuxprobe tmp]# ls -l

total 8

-rwxr--r--. 1 root root 0 Mar 3 04:40 install.txt

-rwxr-xr-x. 1 root root 0 Mar 3 04:41 linuxprobe.txt

[root@linuxprobe tmp]# Getfacl -R . Attributes.txt

...

This command writes the ACL information of all files to the file named permissions.txt.

The following is part of the directory information in the generated permissions.txt file

[root@linuxprobe tmp]# cat permissions.txt

# file: .

# owner: root

# group: root

# flags: --t

user::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::rx

other::rx

# file: permissions .txt

# owner: root

# group: root

user::rw-

group::r--

other::r--

...

3. Modify a file permission, such as: modify linuxprobe.txt and install.txt permissions

[root@ Linuxprobe tmp]# chmod 733 linuxprobe.txt

[root@linuxprobe tmp]# chmod 573 install.txt

[root@linuxprobe tmp]# ls -l

tot Al 8

-r-xrwx-wx. 1 root root 0 Mar 3 04:40 install.txt

-rwx-wx-wx. 1 root root 0 Mar 3 04:41 linuxprobe .txt

-rw-r--r--. 1 root root 4361 Mar 3 04:41 permissions.txt

.....

4.Restore original permissions

1)cd to create permissions.txt Where the directory is located

2) Execute the following command:

setfacl --restore=permissions.txt

You can see the linuxprobe.txt and install.txt permissions restored. >

[root@linuxprobe tmp]# setfacl --restore=permissions.txt

[root@linuxprobe tmp]# ls -l

total 8

- Rwxr--r--. 1 root root 0 Mar 3 04:40 install.txt

-rwxr-xr-x. 1 root root 0 Mar 3 04:41 linuxprobe.txt

-rw-r--r --. 1 root root 4361 Mar 3 04:41 permissions.txt

......

The above is the way to back up and restore Linux file permissions, in order to avoid some careless operation The system files are corrupted. You can learn the above methods to back up and restore files.

Copyright © Windows knowledge All Rights Reserved