How to correctly copy Jenkins directories from the command line?

Article ID:216114868
1 minute readKnowledge base

Issue

Incorrectly copying Jenkins instances can break job symlinks.

This can cause DirectoryNotEmptyException and permalink errors in the logs and prevent job history from loading correctly, even causing job builds to fail.

Environment

  • Linux

Resolution

Copying Jenkins directories to new location on same instance

cp -Rp SOURCE TARGET

The -R switch is for recursive and the -p switch ensures that links are preserved.

Copying Jenkins directories to new location on different instance

rsync -avz -e ssh /src/dir user@remote.host:dst/dir

NOTE Do not use scp to copy Jenkins to another instance as scp does not preserve symlinks.