Certified Jenkins Engineer

Jenkins Administration and Monitoring Part 2

Demo Migrating Jenkins to Another Node

In this step-by-step guide, you’ll learn how to migrate your Jenkins controller—including all configurations, plugins, and jobs—from one VM to another. We’ll walk through creating a backup on the source node, transferring it to the target node, and restoring everything so Jenkins comes up with zero data loss.

Environment Overview

VM NameIP AddressRole
jenkins-controller-164.227.x.xSource node
ubuntu-docker-jdk17-node20165.232.191.207Target node

Prerequisites

  • Jenkins versions must match on both VMs.
  • JDK versions must be identical.
  • You need root (or sudo) access on both machines.

Warning

If the Jenkins or JDK versions differ, you risk plugin incompatibilities or startup failures.
Always verify versions before proceeding.


1. Archive Jenkins on the Source Node

1.1 Connect via SSH

ssh [email protected]

1.2 Verify the Jenkins Home Directory

cd /var/lib
ls -ld jenkins

Note

You should see jenkins owned by the jenkins user with proper read/write permissions.

1.3 Stop and Disable Jenkins

systemctl stop jenkins
systemctl disable jenkins

1.4 Create a Compressed Backup

cd /var/lib
tar -czf jenkins-backup.tar.gz jenkins

1.5 Confirm the Backup

ls -lh jenkins-backup.tar.gz

2. Copy the Backup to the Target Node

Use scp to securely transfer the backup file:

scp /var/lib/jenkins-backup.tar.gz [email protected]:/tmp/

3. Prepare the Target Node

3.1 SSH into the Target

ssh [email protected]

3.2 Inspect Current Jenkins Status

systemctl status jenkins

Note

On fresh installs, Jenkins displays a “Getting Started” page and prompts for an initial admin password. Retrieve it from:

/var/lib/jenkins/secrets/initialAdminPassword

3.3 Stop and Disable Jenkins

systemctl stop jenkins
systemctl disable jenkins

3.4 Deploy the Backup

# Move the tarball into Jenkins home
mv /tmp/jenkins-backup.tar.gz /var/lib/
cd /var/lib

3.5 (Optional) Backup Existing Jenkins Directory

tar -czf jenkins.bak.tar.gz jenkins
rm -rf jenkins

3.6 Extract and Set Permissions

tar -xzf jenkins-backup.tar.gz
chown -R jenkins:jenkins jenkins

4. Start Jenkins on the Target Node

4.1 Enable and Launch the Service

systemctl enable jenkins
systemctl start jenkins

4.2 Verify the Service

systemctl status jenkins

Finally, open your browser to http://165.232.191.207:8080. You should see your familiar Jenkins dashboard with all jobs, credentials, and plugins intact. Congratulations, your Jenkins controller has been successfully migrated!


Watch Video

Watch video content

Previous
Demo Groovy Sandbox and In process Script Approval Part 3