I want to free up space on my Jenkins server and move old projects into cold storage. We have jobs we have not touched for years, but since they were released products we don't want to lose them entirely.
I found the Shelve Project plugin for Jenkins which says:
the data is archived into a tar file and stored on the server
That's a great first step. Now I'd like to find those tar files, and move them to another server.
I had better luck just doing this directly with a small bash script, shown below.
I moved my projects to cold storage by the following:
You can recover them in a similar way by uncompressing the tar file, copying the files to their original location, and reloading Jenkins. After doing that, all the job artifacts and configuration history show properly.
To do this, I created this script:
#!/bin/bash
set -e
# Start of installation-specific configuration
JENKINS_HOME=/var/lib/jenkins
BUILD_DIR=/data/jenkins/builds
ARCHIVE_ROOT=~/testArchive
# End of installation-specific configuration
if [ "$#" -ne 1 ]; then
echo
echo "Usage: "
echo "$0 JenkinsJobName"
echo
echo "Error: Must specify job argument"
echo
exit 1
fi
fileToArchive="$1"
projArchiveRoot="${ARCHIVE_ROOT}/${fileToArchive}"
# First archive the jobs folder
mkdir -p "${projArchiveRoot}/${JENKINS_HOME}/jobs"
mv "${JENKINS_HOME}/jobs/${fileToArchive}" \
"${projArchiveRoot}/${JENKINS_HOME}/jobs/"
# Next archive the configuration history (assuming you use that plug-in)
mkdir -p "${projArchiveRoot}/${JENKINS_HOME}/config-history/jobs"
mv "${JENKINS_HOME}/config-history/jobs/${fileToArchive}" \
"${projArchiveRoot}/${JENKINS_HOME}/config-history/jobs/"
# If you have modified your ${JENKINS_HOME}/config.xml to have a specific
# buildsDir you must also back those up. If you modify these on a
# project-by-project basis using the Advanced options, you must account
# for the build artifacts yourself
mkdir -p "${projArchiveRoot}/${BUILD_DIR}"
mv "${BUILD_DIR}/${fileToArchive}" \
"${projArchiveRoot}/${BUILD_DIR}"
# Now make a single tar file with all the contents for one project
pushd "${projArchiveRoot}"
tar cvzf "${projArchiveRoot}.tar.gz" *
popd
rm -rf ${projArchiveRoot}
# And now instruct the user we're done
echo Archived \"$fileToArchive\" please reload configuration from disk
You likely want to back up your server before you start, and create a test project with configuration history and build artifacts to test with. Once you're comfortable, you can offload huge chunks of data with a few clicks.