Backing up permissions of a filesystem can be useful if you want to revert back to your original permissions after someone else runs the following somewhere in your filesystem tree:
$ chmod -R 777 .
There are at least two ways you backup your filesystem permissions.
pbackup is a very old tool for Unix based systems. It shows the mode_t 16-bit value of a file’s stat information in the standard output. The same information can be stored in a file using redirection.
-S generate backup data from file(s), dump to stdout -R restore permissions from backup through stdin -C check current file permissions against backup -r be recursive (save mode only) -v be verbose (restore mode only) -m <num> max open file descriptors when being recursive (default is 64) -V print version and exit
- Create backup data:
$ pbackup -S -r ~/user > permissions.info
- Check permission integrity:
$ pbackup -C < permissions.info
- Restore from backup:
$ pbackup -R < permissions.info
pbackup is not installed by default on Linux systems. Find the binary compiled on Ubuntu 14.04 amd64 here.
2. ACL backup
Modern Linux systems support Access Control Lists for more fine-grained control information on files. There are two in-built utilities which backup the ownership information in addition to the generic permissions.
- Take snapshot of ACL:
$ getfacl -R ~/user > permissions.info
- Restore ACL snapshot:
$ setfacl --restore=permissions.info