brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: getfacl -R saves the permissions of a whole tree, and setfacl puts them back

Permissions
~/tips/tip-permissions-getfacl-backup-restore

sudo getfacl -R -p srv/data > /root/data-perms.acl

Backs up owners, modes and ACLs of a folder tree to one text file.

Before a big chmod -R or chown -R, I want a way back. getfacl writes the owner, group, mode and ACL of every file to a text file, and setfacl can replay it.

Make the backup from a fixed spot, so the paths are easy to restore:

cd /
sudo getfacl -R -p srv/data > /root/data-perms.acl

-R walks the whole tree and -p keeps absolute paths without stripping the leading slash. The file is plain text, one block per file, so you can read or grep it too.

When the change went wrong, restore it:

cd /
sudo setfacl --restore=/root/data-perms.acl

The restore sets the ACL entries, and as root it also puts back owner and group, which makes it a full undo for permission changes. Files that were added after the backup are left as they are, and files that are gone are reported as errors.

The file only stores names, not numbers, for users and groups. On another machine, or after you renumbered accounts, the names map to whatever those accounts are there. Also run the restore from the same directory as the backup when you didn’t use -p, because the paths are relative then. And it saves permissions only, not file contents, so it doesn’t replace a real backup.

Further reading: setfacl(1) manual page, getfacl(1) manual page

More Permissions tips sudo su -s /bin/bash www-data sudo setfacl -R -d -m g:media:rwX /srv/media sudo cp -r /srv/site /srv/site.r ls -ln /srv/data newgrp media All Permissions tips (30) All topics

Link