#!/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 2 ]; then | |
echo usage: $0 root_dir jenkins_master | |
exit 1 | |
fi | |
ROOT_DIR=$1 | |
JENKINS_MASTER=$2 | |
ORIG_DIR=$PWD | |
mkdir -p $ROOT_DIR | |
cd $ROOT_DIR | |
rm -rf *-jenkins-git | |
git clone git@GIT_SERVER:${JENKINS_MASTER}-jenkins-git.git | |
cd $ROOT_DIR/${JENKINS_MASTER}-jenkins-git | |
# rsync-no-vanished is just a wrapper making sure rsync doesn't fail on vanished files during the process. | |
# Jenkins master is in a subdirectory of /var/lib/jenkins. | |
$ORIG_DIR/rsync-no-vanished -av --delete --exclude="jobConfigHistory" \ | |
--exclude="war" \ | |
--exclude="config-history" \ | |
--exclude=".hudson" \ | |
--exclude=".ivy2" \ | |
--exclude=".m2" \ | |
--exclude="lost+found" \ | |
--include="*/" \ | |
--include="*config.xml" \ | |
--include="users/*" \ | |
--include="*.hpi" \ | |
--include="*.jpi" \ | |
--include="*pinned" \ | |
--include="*disabled" \ | |
--exclude="*" \ | |
--prune-empty-dirs /var/lib/jenkins/${JENKINS_MASTER}/ . | |
[ -d /var/lib/jenkins/${JENKINS_MASTER}/scriptler ] && $ORIG_DIR/rsync-no-vanished -av --delete /var/lib/jenkins/${JENKINS_MASTER}/scriptler . | |
[ -d /var/lib/jenkins/${JENKINS_MASTER}/secrets ] && $ORIG_DIR/rsync-no-vanished -av --delete /var/lib/jenkins/${JENKINS_MASTER}/secrets . | |
cp /var/lib/jenkins/${JENKINS_MASTER}/*.xml . | |
cp /var/lib/jenkins/${JENKINS_MASTER}/*.key . | |
git add -A | |
git commit -m "Jenkins ${JENKINS_MASTER} config backup for $(date)" | |
git push origin master |
This comment has been minimized.
This comment has been minimized.
First (and foremost) Thanks for this. I realize it is an old post, so I'll completely understand if you don't reply. Nevertheless, I would appreciate:
and, last, but not least: |
This comment has been minimized.
This comment has been minimized.
eh, I don't think it is good enough, so I fork it to my repos, and improve it plus my mind. |
This comment has been minimized.
This comment has been minimized.
Thanks for all your sharing. Wonder if there is a way to backup a specific plan/project and how to retrieve it? |
This comment has been minimized.
Thanks for sharing. You just saved me a lot of time.