Copy everything from one directory to another directory on a different volume in Unix, while retaining permissions, ownership, structure, as well as all creation and modification dates (timestamps)
When Destination is Fresh
rsync -avHAX --numeric-ids /source/directory/ /destination/directory/
Caution - removes destination files
rsync -avHAX --numeric-ids --delete /source/directory/ /destination/directory/
-a
,--archive
: This option enables archive mode, which is equivalent to-rlptgoD
. It ensures that symbolic links, devices, attributes, permissions, ownerships, etc., are preserved in the copy. Additionally, it recurses into directories.-v
,--verbose
: This option provides verbose output, showing the details of the transfer.-H
: This option preserves hard links, ensuring that hard-linked files in the source directory are also hard-linked in the destination directory.-A
: This option preserves Access Control Lists (ACLs) to maintain the exact access control information.-X
: This option preserves extended attributes, which are used to store extra data and settings on files and directories.--numeric-ids
: This ensures that numeric user and group IDs are preserved, which is particularly useful when copying files to a system where the user and group names might not exist.--delete
: This option deletes extraneous files from the destination directory to ensure that the destination is an exact copy of the source. Use this option with caution, especially if the destination directory contains data that might not exist in the source directory.