-
-
Save kundancool/cf4d0e306a5641a71e24aeab9adce358 to your computer and use it in GitHub Desktop.
Example of a script for backing up Jenkins config in git.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 [email protected]:/var/lib/jenkins [email protected]:choldrim/deepin-jenkins-git.git deepin-jenkins-git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment