Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create volume backup of Jenkins in Docker

Tags:

docker

jenkins

I have a Jenkins installation in Docker and I need to create backups and restore them when I need. I tried some plugins but because I'm using docker they don't work. Besides that, I need to backup everything including historic.

I stumbled on this page: https://medium.com/pacroy/how-to-backup-and-restore-your-jenkins-data-volume-in-docker-2ac66d99315a

but the instructions are for windows and I can't adapt that to my linux environment.

My question is: how can I create full backups of my jenkins instance in docker in a way that I can restore it or even create a copy in another machine.

like image 676
zephirus Avatar asked Mar 06 '23 22:03

zephirus


2 Answers

All the Jenkins data including job configuration and builds are stored under /var/jenkins_home inside the container.

Thus you can simply backup this folder and all the Jenkins state will be persisted. You can regularly copy this folder from the container using:

docker cp <jenkins-container-name>:/var/jenkins_home ./jenkins_home

You from anyone of these backup you can start a new jenkins instance using the command:

docker run -v ./jenkins_volume:/var/jenkins_home -p 8080:8080 jenkins ...
like image 159
yamenk Avatar answered Mar 15 '23 18:03

yamenk


My user is admin, my backup folder is data. After copying jenkins backupfolder to new place you need change owner and start as usual (my example is on docker-compose)

sudo chown admin:admin docker-compose.yml 
sudo chown -R 1000:1000 data/

official dockerfile - link - Jenkins is run with user jenkins, uid = 1000

docker hub

like image 43
Vadym Avatar answered Mar 15 '23 18:03

Vadym