Stop tar from destroying your hard links during a server migration

Backup & Recovery (Rsync/Tar/Dd)

Stop tar from destroying your hard links during a server migration

🧩 The Challenge

Moving a directory structure only to realize all your hard-linked files are now taking up double the space on the destination disk is a special kind of nightmare. I learned that lesson the hard way when I ran out of storage mid-migration because the filesystem thought every duplicate link was a fresh file.

💡 The Fix

You need to tell tar specifically to preserve those links instead of dereferencing them into individual copies. It saves you tons of disk space and keeps the inode structure intact on the new server.

tar --hard-dereference -cvf - /source/directory | tar --hard-dereference -xvf - -C /destination/directory

⚙️ Why It Works

Adding that flag tells the archiver to store the hard link information rather than treating each link as a unique file contents block. It preserves the relationship between files that share the same underlying data, which is usually exactly what you want when moving backups.

🚀 Pro-Tip: Always run a quick du -sh on the source and destination afterward just to make sure the math actually adds up.

Linux Tips & Tricks | © ngelinux.com | 7/25/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted