Skip to content

Symlink races during cPanel backup and restore — what to watch

Symbolic links inside a cPanel home can cause backup tools to follow into directories they shouldn't, or restore into paths that don't exist. The classes of problem and how to avoid them.

Symbolic links in a customer’s home directory are usually benign. Sometimes they’re not — a symlink pointing to /var/log or /etc can cause a poorly-configured backup tool to descend into system directories. Worse, on restore, a symlink to a path that didn’t exist on the source server creates a different file at the destination.

What’s happening

cPanel backups normally exclude system directories and traverse customer homes with -h (preserve symlinks). The risk is when a customer creates a symlink inside their home that points outside their home — usually accidentally, sometimes maliciously. Default JetBackup and pkgacct handle this correctly. Custom backup scripts that use plain tar or rsync without explicit symlink handling can be confused.

The restore-side issue: if a symlink was created on the source server pointing to a path that doesn’t exist on the destination, the symlink restores fine but breaks at first dereference.

How to verify

Audit symlinks in customer homes:

find /home/<user> -type l -ls
find /home/<user> -type l -printf "%p -> %l\n" | grep -v '^/home/'
find /home/<user> -type l -printf "%p -> %l\n" | grep -E '^/(etc|var|usr|root)'

Symlinks pointing outside /home/<user> are suspect — either user error or, rarely, abuse.

The fix

  1. JetBackup handles symlinks correctly by default; verify with tar -tzhf <snapshot>/homedir.tar | head (the h flag tells you whether tar followed links).
  2. For audit purposes, generate a per-account symlink report: find /home/<user> -type l > /var/cpanel/audits/<user>-symlinks.txt. Compare across audits — new external symlinks deserve a look.
  3. If you find a malicious symlink, remove it before the next backup: rm /home/<user>/path/to/symlink. Document in the security log.
  4. On restore, run a post-restore validation: find /home/<user> -type l ! -exec test -e {} \; -print lists broken symlinks. Common after cross-server restores; the operator decides whether to recreate the target or remove the symlink.
  5. Customer-facing communication: “we found a few broken symlinks in your account after restore, here is the list, please confirm whether they need their targets recreated.”

Stack Harbor includes symlink auditing in account onboarding under managed cPanel operations.