rsync -aAXH –numeric-ids –info=progress2 /var/ /mnt/newvar/
This command is a classic way to perform a full system-level migration of a directory while keeping every bit of metadata intact.
Here is the breakdown of each option:
-a(Archive mode): This is a shortcut for several flags. It preserves symbolic links, permissions, modification times, groups, and owners. It also ensures the copy is recursive.-A(ACLs): Preserves Access Control Lists. This ensures that any specific user/group permissions set outside of standard Linux “rwx” permissions are carried over.-X(Extended Attributes): Preserves “xattrs” (like security labels or user-defined metadata). This is vital for systems using SELinux.-H(Hard links): Tells rsync to look for hard links in the source and recreate them in the destination. Without this, rsync would copy each hard link as a separate, full file, wasting disk space.--numeric-ids: Tells rsync to transfer the UID/GID numbers as they are, rather than trying to map them by username/group name. This is crucial when copying to a drive that will be used by a different OS or a “Live” environment where the user IDs might not match yet.--info=progress2: Provides a modern, single-line progress bar for the entire transfer (showing total percentage and speed) rather than listing every single file as it goes.