Backup, restore file permissions

cool_penguin_smallBacking 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.

1. pbackup

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.

Options

  -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

Usage

  • 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.
md5sum: baf69a372ddd7237a3e4af42f8097182

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

One thought on “Backup, restore file permissions”

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s