Skip to content

Commit

Permalink
#104 Backups should only exclude config.xml in top level job directories
Browse files Browse the repository at this point in the history
  • Loading branch information
pbecotte authored and tomaszsek committed Jan 18, 2020
1 parent bf07fa5 commit c6c3987
Show file tree
Hide file tree
Showing 16 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions backup/pvc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.9
FROM debian:buster-slim

ENV USER=user
ENV UID=1000
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backup/pvc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion backup/pvc/bin/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build.xml
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build logs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
3 changes: 2 additions & 1 deletion backup/pvc/e2e/backup_and_restore/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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

0 comments on commit c6c3987

Please sign in to comment.