> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Migrating Jenkins to Another Node

> This article provides a step-by-step guide to migrate a Jenkins controller from one VM to another without data loss.

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 Name                    | IP Address      | Role        |
| -------------------------- | --------------- | ----------- |
| jenkins-controller-1       | 64.227.x.x      | Source node |
| ubuntu-docker-jdk17-node20 | 165.232.191.207 | Target node |

## Prerequisites

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

<Callout icon="triangle-alert" color="#FF6B6B">
  If the Jenkins or JDK versions differ, you risk plugin incompatibilities or startup failures.\
  Always verify versions before proceeding.
</Callout>

***

## 1. Archive Jenkins on the Source Node

### 1.1 Connect via SSH

```bash theme={null}
ssh root@64.227.x.x
```

### 1.2 Verify the Jenkins Home Directory

```bash theme={null}
cd /var/lib
ls -ld jenkins
```

<Callout icon="lightbulb" color="#1CB2FE">
  You should see `jenkins` owned by the `jenkins` user with proper read/write permissions.
</Callout>

### 1.3 Stop and Disable Jenkins

```bash theme={null}
systemctl stop jenkins
systemctl disable jenkins
```

### 1.4 Create a Compressed Backup

```bash theme={null}
cd /var/lib
tar -czf jenkins-backup.tar.gz jenkins
```

### 1.5 Confirm the Backup

```bash theme={null}
ls -lh jenkins-backup.tar.gz
```

***

## 2. Copy the Backup to the Target Node

Use `scp` to securely transfer the backup file:

```bash theme={null}
scp /var/lib/jenkins-backup.tar.gz root@165.232.191.207:/tmp/
```

***

## 3. Prepare the Target Node

### 3.1 SSH into the Target

```bash theme={null}
ssh root@165.232.191.207
```

### 3.2 Inspect Current Jenkins Status

```bash theme={null}
systemctl status jenkins
```

<Callout icon="lightbulb" color="#1CB2FE">
  On fresh installs, Jenkins displays a “Getting Started” page and prompts for an initial admin password. Retrieve it from:

  ```text theme={null}
  /var/lib/jenkins/secrets/initialAdminPassword
  ```
</Callout>

### 3.3 Stop and Disable Jenkins

```bash theme={null}
systemctl stop jenkins
systemctl disable jenkins
```

### 3.4 Deploy the Backup

```bash theme={null}
# Move the tarball into Jenkins home
mv /tmp/jenkins-backup.tar.gz /var/lib/
cd /var/lib
```

### 3.5 (Optional) Backup Existing Jenkins Directory

```bash theme={null}
tar -czf jenkins.bak.tar.gz jenkins
rm -rf jenkins
```

### 3.6 Extract and Set Permissions

```bash theme={null}
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

```bash theme={null}
systemctl enable jenkins
systemctl start jenkins
```

### 4.2 Verify the Service

```bash theme={null}
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!

***

## Links and References

* [Jenkins LTS Download](https://www.jenkins.io/download/)
* [Jenkins Backup & Restore Guide](https://www.jenkins.io/doc/book/system-administration/backing-up/)
* [Using systemctl](https://www.freedesktop.org/software/systemd/man/systemctl.html)
* [Secure Copy (scp) Documentation](https://linux.die.net/man/1/scp)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-jenkins-engineer/module/90da5b24-e8f2-455a-9756-9d69f4a7ce8e/lesson/9b72e855-b55c-4fd1-ad5d-c81c39afc77a" />
</CardGroup>
