-
-
Save dimitrystd/8ca7d10d8287acc1ff68 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 | |
# Modified version of https://gist.github.com/choldrim/b0862264bda0f6a2e4ae and | |
# https://gist.github.com/abayer/527063a4519f205efc74 | |
# 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 -c user.name="Connectors team" -c user.email="[email protected]" \ | |
${GIT_REMOTE_URL} ${GIT_REPOS_NAME} | |
cd ${GIT_REPOS_NAME} | |
rsync -av --delete \ | |
--exclude="jobConfigHistory" \ | |
--exclude="war" \ | |
--exclude="config-history" \ | |
--exclude=".hudson" \ | |
--exclude=".ivy2" \ | |
--exclude=".m2" \ | |
--exclude="lost+found" \ | |
--exclude="/plugins" \ | |
--exclude="/jobs/*/builds" \ | |
--include="*/" \ | |
--include="*config.xml" \ | |
--include="/jobs/*/config.xml" \ | |
--include="/jobs/*/nextBuildNumber" \ | |
--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 |
Good add, the only thing missing, I believe, is
--include=".ssh/*" \
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rsync
parameters listrsync
list