Site icon New Generation Enterprise Linux

Stop tar from losing your mind over symlink permissions

Backup & Recovery (Rsync/Tar/Dd)

Stop tar from losing your mind over symlink permissions

đź§© The Challenge

You finally finish pulling a massive archive of your config directories, but when you extract it on the destination server, half the symlinks are broken and the permissions are garbage. I’ve wasted a whole afternoon re-fixing ownerships because I forgot that tar doesn’t always play nice with the metadata of special files.

đź’ˇ The Fix

Use the specific flags that force tar to preserve the hard links and file attributes, or you’re just going to have a pile of broken shortcuts. This makes sure the archive actually represents the filesystem structure instead of just a loose bag of bits.

tar --xattrs --selinux --acls --hard-dereference -cvpf archive.tar.gz /source/directory

⚙️ Why It Works

Adding these flags forces tar to capture extended attributes and SELinux contexts, which are usually dropped by default. Hard dereferencing ensures you get the actual file content instead of just a pointer that dies the moment you move the directory.

🚀 Pro-Tip: If you’re moving between different filesystems, double-check that the destination supports those same xattrs or the restoration will throw warnings you can’t ignore.

Linux Tips & Tricks | © ngelinux.com | 8/6/2026

0 0 votes
Article Rating
Exit mobile version