手动备份
sudo systemctl stop jenkinssudo tar -czvf jenkins_backup.tar.gz /var/lib/jenkins/{config.xml,jobs,users,plugins}使用插件备份
Shell脚本自动备份
#!/bin/bash
JENKINS_HOME="/var/lib/jenkins"
BACKUP_DIR="/backups/jenkins_$(date +%Y%m%d)"
mkdir -p $BACKUP_DIR
tar -czvf $BACKUP_DIR/jenkins_backup_$(date +%Y%m%d).tar.gz -C $JENKINS_HOME .
cron设置定时任务(如每天凌晨执行)。手动恢复
sudo systemctl stop jenkinssudo tar -xzvf jenkins_backup.tar.gz -C /var/lib/jenkinssudo systemctl start jenkins插件恢复