Permission Rescue: getfacl to Save Your Future Self
Luke Hebert
- 2 minutes read - 297 wordsLosing file permissions after a migration, a failed restore, or a misapplied chmod can lock you out of critical data in a hurry. The good news is that Linux gives you a clean, two-command workflow to snapshot and restore the full permission set of any directory tree.
Backing Up Permissions
Use getfacl in recursive mode to capture every file and folder’s ACL, ownership, and mode into a single text file:
getfacl -R /path/to/directory > perms.to.restoreThe -R flag walks the entire subtree. The output is a plain-text file that includes owner, group, mode, and any extended ACL entries for each path.
Restoring Permissions
When you are ready to put everything back, feed that file to setfacl:
setfacl --restore=perms.to.restoreA few things to keep in mind:
--restoreexpects the exact format produced bygetfacl -R(or a compatible tool).- If the backup contains owner or group comments and you run
setfaclas root, the owner and owning group of every file are restored as well. - This option cannot be combined with other
setfacloptions, with the single exception of--test.
Dry Run with --test
Before committing a large restore, preview what would change:
setfacl --restore=perms.to.restore --test--test prints the actions it would take without actually modifying the filesystem, so you can verify the scope before the real run.
Quick Tips
- Store the backup file somewhere outside the directory tree you are backing up, so a restore of that tree does not overwrite the backup itself.
- If you only need to restore a subset, you can filter the text file with
greporawkbefore passing it tosetfacl --restore. - Permissions restored this way include extended ACLs, not just the standard rwx bits, which makes this approach more complete than a simple
chmodorchownpass.