-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jenkins config rescue #27
Comments
Backup without writing to disk on the remote hostSometimes it is necessary to read-only backup on the remote host. The following script is designed to backup Jenkins on a remote host that is read-only. Source code for `backup.sh` (Click to expand)#!/bin/bash
#Created by Sam Gleske (https://github.com/samrocketman)
#Thu Sep 10 17:38:28 EDT 2020
# DESCRIPTION
# Take a remote backup of Jenkins configuration without writing to disk on
# the remote host.
#
# USAGE
# Backup Jenkins at a standard path
#
# ./backup.sh user@host > local-file.tgz
#
# Backup Jenkins with a custom home location.
#
# ./backup.sh user@host /var/lib/jenkins > local-file.tgz
#
# Backup Jenkins with a custom home location and changing the default depth
# for searching for job configurations. For a classic Jenkins instance with
# no folder hierarchy the recommended depth to search configuration is 2.
#
# ./backup.sh user@host /var/lib/jenkins 2 > local-file.tgz
REMOTE_HOST="$1"
BACKUP_PATH="${2:-/var/lib/jenkins}"
# jervis Jenkins instances require a depth of 7 to capture folders,
# multibranch pipelines, and job next build numbers.
MAX_DEPTH="${3:-7}"
ssh -T "${REMOTE_HOST}" -- 'sudo -- /bin/bash -o pipefail -ex' <<EOF
echo 'Backup as the following user:' >&2
whoami >&2
cd '${BACKUP_PATH}'
find . \
-maxdepth '${MAX_DEPTH}' \( \
-path './config-history/*' \
-o -path './plugins/*' \
-o -path './secret*' \
-o -path './*.xml' \
-o -path './jenkins-versions.manifest' \
-o -path './*.groovy.d/*' \
-o -path './userContent/*' \
-o -type f \( \
-name 'config.xml' \
-o -name 'nextBuildNumber' \
\) \
\) \
| sed 's#^./##' \
| tar czT -
EOF
#this will output a compressed archive to stdout Example usageThe following example will execute
The script supports up to 3 arguments:
Customize the user home (
To backup a remote Jervis-based Jenkins instance, the following command should be used (
Encrypt local backupsI prefer GPG. The following is an example using my own GPG key.
Example outputWhen a backup successfully runs you should see output similar to the following.
If you encrypted your backup locally, then you'll need to decrypt it.
To extract your local backup run the following.
Cross-platform issuesPlease note, if your |
Back up jenkins config without build history.
The text was updated successfully, but these errors were encountered: