How to preserve symlinks when copying with rsync

Symbolic links often carry release pointers, shared asset paths, or configuration indirection that should remain links after a copy. Dereferencing those links during a sync can copy the target content instead, which changes the destination layout and can make later rollbacks or release switches behave differently.

The -a archive option includes -l, which tells rsync to copy symlinks as symlinks. Avoid --copy-links and -L when the destination should keep the link object, because those options copy the file or directory the link points to instead of the link itself.

A preserved symlink keeps the same link target text. Relative links usually keep working when the surrounding directory tree is copied together, while absolute links can still point back to an old location outside the destination tree. Verify both the link type and the resolved target before treating a copied release or configuration tree as ready.

  1. Inspect the source symlink before copying.
    $ ls -l /srv/source/current
    lrwxrwxrwx 1 root root 19 Jun  6 04:01 /srv/source/current -> releases/2026-06-06
  2. Copy the source tree with archive mode so symlinks are preserved.
    $ rsync -a --itemize-changes /srv/source/ /srv/destination/
    cL+++++++++ current -> releases/2026-06-06
    cd+++++++++ releases/
    cd+++++++++ releases/2026-06-06/
    >f+++++++++ releases/2026-06-06/VERSION

    The cL itemized marker shows that rsync created a symlink at the destination.

  3. Confirm that the destination path is still a symlink.
    $ ls -l /srv/destination/current
    lrwxrwxrwx 1 root root 19 Jun  6 04:01 /srv/destination/current -> releases/2026-06-06
  4. Confirm that the destination symlink points to the expected target text.
    $ readlink /srv/destination/current
    releases/2026-06-06
  5. Read a file through the copied symlink when the target tree was copied with it.
    $ cat /srv/destination/current/VERSION
    release 2026-06-06

    Do not add --copy-links, -L, or --copy-dirlinks unless the destination should receive target content instead of the symlink itself.

  6. Review absolute or outside-tree symlinks before using the destination.
    $ find /srv/destination -xtype l -print

    A listed path is a symlink whose target cannot be reached from the destination tree. Fix the target or copy the missing target before using the destination.