手动备份
sudo systemctl stop jenkins/var/lib/jenkins(主目录,含配置、插件、任务等)、/etc/default/jenkins(配置文件)。tar打包:tar -czvf jenkins_backup.tar.gz /var/lib/jenkins。插件备份
自动化备份(脚本+定时任务)
backup_jenkins.sh),使用tar打包主目录,通过crontab定时执行(如每天凌晨2点)。#!/bin/bash
JENKINS_HOME="/var/lib/jenkins"
BACKUP_DIR="/backup/jenkins_$(date +%Y%m%d)"
mkdir -p $BACKUP_DIR
tar -czvf $BACKUP_DIR/jenkins_backup.tar.gz $JENKINS_HOME
手动恢复
sudo systemctl stop jenkinstar -xzvf jenkins_backup.tar.gz -C /var/lib/jenkins。sudo systemctl start jenkins。插件恢复
从Git恢复(若配置存储在Git仓库)
git pull,确保Jenkinsfile及脚本同步。参考来源: