Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of a script for backing up Jenkins config in git.
#!/bin/bash
# Copies certain kinds of known files and directories from a given Jenkins master directory
# into a git repo, removing any old ones, adds 'em, commits 'em, pushes 'em.
set -ex
if [ $# -ne 3 ]; then
echo usage: $0 jenkins_home git_repos_url git_repos_name
exit 1
fi
JENKINS_HOME=$1
GIT_REMOTE_URL=$2
GIT_REPOS_NAME=$3
rm -rf ${GIT_REPOS_NAME}
git clone ${GIT_REMOTE_URL}
cd ${GIT_REPOS_NAME}
rsync -av --delete --exclude="jobConfigHistory" \
--exclude="war" \
--exclude="config-history" \
--exclude=".hudson" \
--exclude=".ivy2" \
--exclude=".m2" \
--exclude="lost+found" \
--include="*config.xml" \
--include="jobs/*/builds/*/log" \
--include="users/*" \
--include="*.hpi" \
--include="*.jpi" \
--include="*pinned" \
--include="*disabled" \
--include="scriptler/*" \
--include="secrets/*" \
--include="*.xml" \
--include="*.key" \
--exclude="*" \
--prune-empty-dirs ${JENKINS_HOME}/ .
git add -A
git commit -m "Jenkins ${JENKINS_MASTER} config backup for $(date)"
git push origin master
## example
# ./jenkins-git-backup.sh jenkins@10.0.2.196:/var/lib/jenkins git@git.oschina.net:choldrim/deepin-jenkins-git.git deepin-jenkins-git
@Lake-end

This comment has been minimized.

Copy link

commented Dec 18, 2017

rm -rf ${GIT_REPOS_NAME}
You are one messed up paramater away from deleting your Jenkins_home

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.