So I've been looking into a backup script that will allow us to keep a backup of the configuration. We use Maven for most of our builds, so the released artifacts are in our Maven Repository (which is hosted on two servers each with RAID arrays and using DRBD to mirror between the pair, with an rsync to a NAS in another cabinet and we are trying to get an rsych to an off-site storage going as well).
There seem to be two main options:
- Use the Hudson Backup Plugin.
- Backup your Hudson configuration to Source Control.
So a quick search of the interwebs revealed Mike Rooney has been here before... cool... I have somewhere to start... with a few tweaks I have ended up with the following:
#!/bin/bash
if [[ ! -d $HUDSON_HOME ]]
then
echo "Hudson home directory ($HUDSON_HOME) is missing or undefined"
exit 1
fi
cd $HUDSON_HOME
# Add any new conf files, jobs, users, and content.
svn add -q --parents *.xml jobs/*/config.xml users/*/config.xml userContent/*
# Add the names of plugins so that we know what plugins we have
ls -l plugins > plugins.list
svn add -q -N --parents plugins.list
# Ignore things in the root we don't care about.
echo -e "war\nlog\n*.log\n*.tmp\n*.old\n*.bak\n*.jar\n*.json\nsecret.key\ntools\nshelvedProjects\n.owner\nupdates\nplugins" > myignores
svn ps -q svn:ignore -F myignores . && rm myignores
# Ignore things in jobs/* we don't care about.
echo -e "builds\nlast*\nnext*\n*.txt\n*.log\nworkspace*\ncobertura\njavadoc\nhtmlreports\nncover\ndoclinks" > myignores
svn ps -q svn:ignore -F myignores jobs/* && rm myignores
# Remove anything from SVN that no longer exists in Hudson.
svn st | sed -n -e "s/^\!//p" | xargs -r svn rm
# And finally, check in of course, showing status before and after for logging.
svn st && svn ci --non-interactive --username=hudson-build -m "automated commit of Hudson configuration" && svn st
if [[ ! -d $HUDSON_HOME ]]
then
echo "Hudson home directory ($HUDSON_HOME) is missing or undefined"
exit 1
fi
cd $HUDSON_HOME
# Add any new conf files, jobs, users, and content.
svn add -q --parents *.xml jobs/*/config.xml users/*/config.xml userContent/*
# Add the names of plugins so that we know what plugins we have
ls -l plugins > plugins.list
svn add -q -N --parents plugins.list
# Ignore things in the root we don't care about.
echo -e "war\nlog\n*.log\n*.tmp\n*.old\n*.bak\n*.jar\n*.json\nsecret.key\ntools\nshelvedProjects\n.owner\nupdates\nplugins" > myignores
svn ps -q svn:ignore -F myignores . && rm myignores
# Ignore things in jobs/* we don't care about.
echo -e "builds\nlast*\nnext*\n*.txt\n*.log\nworkspace*\ncobertura\njavadoc\nhtmlreports\nncover\ndoclinks" > myignores
svn ps -q svn:ignore -F myignores jobs/* && rm myignores
# Remove anything from SVN that no longer exists in Hudson.
svn st | sed -n -e "s/^\!//p" | xargs -r svn rm
# And finally, check in of course, showing status before and after for logging.
svn st && svn ci --non-interactive --username=hudson-build -m "automated commit of Hudson configuration" && svn st
The main changes are that I've updated the root level ignores and I capture a listing of the plugins directory so that you can know exactly what plugins you had installed
Glad my post helped, and thanks for the improvements. I like the idea of including the plugin list so I think I shall add that as well!
ReplyDeleteI considered just keeping the plugins directory under VC as well as a lot of jobs may not work without installing them, but it can be rather large.
Thanks, got to give it a try, either way. I didn't even know about the Backup Plugin.
ReplyDeleteThanks for this - it inspired me to write a similar script for use with git (which interestingly turns out to be simpler syntactically).
ReplyDeletealso add:
ReplyDeletejobs/*/promotions/*/config.xml
if you use the promotions plugin.
svn st | sed -n -e "s/^\!//p" | xargs -r svn rm
ReplyDeletewould fail if some dir/file contains spaces (think about a job named "test delete" that was removed)
I'm using this instead:
svn st | sed -n -e "s/^\(\!\s*\)\(.*\)/\"\2\"/p" | xargs -r svn rm