in Python

[ Script ] How To Backup and Restore Directory Permissions on Linux Machines

There is many ways to backup and restore on Linux machines, but when you have a specific need you must use some sort of scripting, don’t rely on tools because i think this get you stuck in thinking that there no other way to do the thing you need to do.

The requirement was that we need a script to backup and restore Linux directory permissions until a certain depth, for example, we need to backup permissions of the source directory /root and three directories beneath it.

Using the script is straightforward: you need to update 4 variable:

sourceDir: The source directory to use as a backup source
extractOut: The file that will store the backed up permission. This file is also used as the source of the permissions to restore
op: The operation to execute: B= Backup / R= Restore
level: The directory depth level to scan

With some minor tweaks it can also be used on Windows machines.

The script backup and restore standard Linux permissions, it doesn’t handle ACL entries nor SElinux context.

You can get it here on my Github repo.

Share your thoughts