#104 Backups should only exclude config.xml in top level job directories

This commit is contained in:
Paul Becotte 2020-01-16 18:56:17 -05:00 committed by Tomasz Sęk
parent bf07fa59ef
commit c6c3987588
No known key found for this signature in database
GPG Key ID: DC356D23F6A644D0
16 changed files with 15 additions and 6 deletions

View File

@ -1,4 +1,4 @@
FROM alpine:3.9
FROM debian:buster-slim
ENV USER=user
ENV UID=1000
@ -10,8 +10,8 @@ RUN addgroup --gid "$GID" "$USER" && \
--gecos "" \
--ingroup "$USER" \
--uid "$UID" \
"$USER" && \
apk add --no-cache bash
"$USER"
WORKDIR /home/user/bin
COPY bin .
RUN chmod +x *.sh

View File

@ -67,7 +67,7 @@ endif
define e2e
echo "\nRunning $(1) e2e test";
@e2e/$(1)/test.sh $(DOCKER_REGISTRY)-$(NAME):$(GITCOMMIT);
@e2e/$(1)/test.sh $(DOCKER_REGISTRY)-$(NAME):$(GITCOMMIT)
endef
.PHONY: docker-e2e

View File

@ -10,7 +10,11 @@ BACKUP_TMP_DIR=$(mktemp -d)
backup_number=$1
echo "Running backup"
tar -C ${JENKINS_HOME} -czf "${BACKUP_TMP_DIR}/${backup_number}.tar.gz" --exclude jobs/*/config.xml --exclude jobs/*/workspace* -c jobs && \
# config.xml in a job directory is a config file that shouldnt be backed up
# config.xml in child directores is state that should. For example-
# branches/myorg/branches/myrepo/branches/master/config.xml should be retained while
# branches/myorg/config.xml should not
tar -C ${JENKINS_HOME} -czf "${BACKUP_TMP_DIR}/${backup_number}.tar.gz" --exclude jobs/*/workspace* --no-wildcards-match-slash --anchored --exclude jobs/*/config.xml -c jobs && \
mv ${BACKUP_TMP_DIR}/${backup_number}.tar.gz ${BACKUP_DIR}/${backup_number}.tar.gz
[[ ! -s ${BACKUP_DIR}/${backup_number}.tar.gz ]] && echo "backup file '${BACKUP_DIR}/${backup_number}.tar.gz' is empty" && exit 1;

View File

@ -16,6 +16,7 @@ fi
JENKINS_HOME="$(pwd)/jenkins_home"
BACKUP_DIR="$(pwd)/backup"
RESTORE_FOLDER="$(pwd)/restore"
JENKINS_HOME_AFTER_RESTORE="$(pwd)/jenkins_home_after_restore"
mkdir -p ${BACKUP_DIR}
mkdir -p ${RESTORE_FOLDER}
@ -35,6 +36,6 @@ backup_file="${BACKUP_DIR}/${backup_number}.tar.gz"
docker exec -it ${cid} /bin/bash -c "JENKINS_HOME=${RESTORE_FOLDER};/home/user/bin/restore.sh ${backup_number}"
echo "Compare directories"
diff --brief --recursive ${JENKINS_HOME} ${RESTORE_FOLDER}
diff --brief --recursive "${RESTORE_FOLDER}" "${JENKINS_HOME_AFTER_RESTORE}"
echo "Directories are the same"
echo PASS