diff --git a/backup/pvc/Dockerfile b/backup/pvc/Dockerfile index 7109d932..3f4ebbc5 100644 --- a/backup/pvc/Dockerfile +++ b/backup/pvc/Dockerfile @@ -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 diff --git a/backup/pvc/Makefile b/backup/pvc/Makefile index cf19a7c1..eb8faad2 100644 --- a/backup/pvc/Makefile +++ b/backup/pvc/Makefile @@ -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 diff --git a/backup/pvc/bin/backup.sh b/backup/pvc/bin/backup.sh index 71a8f8e7..b8dfa98c 100644 --- a/backup/pvc/bin/backup.sh +++ b/backup/pvc/bin/backup.sh @@ -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; diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/config.xml b/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/config.xml new file mode 100644 index 00000000..e69de29b diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/jobs/branchjob/branches/master/build b/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/jobs/branchjob/branches/master/build new file mode 100644 index 00000000..e69de29b diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/jobs/branchjob/branches/master/config.xml b/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/jobs/branchjob/branches/master/config.xml new file mode 100644 index 00000000..e69de29b diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/jobs/branchjob/config.xml b/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/jobs/branchjob/config.xml new file mode 100644 index 00000000..e69de29b diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/some-job/builds/1/build.xml b/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/some-job/builds/1/build.xml new file mode 100644 index 00000000..5d0bb326 --- /dev/null +++ b/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/some-job/builds/1/build.xml @@ -0,0 +1 @@ +build.xml \ No newline at end of file diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/some-job/config.xml b/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/some-job/config.xml new file mode 100644 index 00000000..e69de29b diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/orgjob/jobs/branchjob/branches/master/build b/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/orgjob/jobs/branchjob/branches/master/build new file mode 100644 index 00000000..e69de29b diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/orgjob/jobs/branchjob/branches/master/config.xml b/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/orgjob/jobs/branchjob/branches/master/config.xml new file mode 100644 index 00000000..e69de29b diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/orgjob/jobs/branchjob/config.xml b/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/orgjob/jobs/branchjob/config.xml new file mode 100644 index 00000000..e69de29b diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/some-job/builds/1/build.xml b/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/some-job/builds/1/build.xml new file mode 100644 index 00000000..5d0bb326 --- /dev/null +++ b/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/some-job/builds/1/build.xml @@ -0,0 +1 @@ +build.xml \ No newline at end of file diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/some-job/builds/1/log b/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/some-job/builds/1/log new file mode 100644 index 00000000..7f236fe6 --- /dev/null +++ b/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/some-job/builds/1/log @@ -0,0 +1 @@ +build logs \ No newline at end of file diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/some-job/nextBuildNumber b/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/some-job/nextBuildNumber new file mode 100644 index 00000000..d8263ee9 --- /dev/null +++ b/backup/pvc/e2e/backup_and_restore/jenkins_home_after_restore/jobs/some-job/nextBuildNumber @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git a/backup/pvc/e2e/backup_and_restore/test.sh b/backup/pvc/e2e/backup_and_restore/test.sh index b392d63b..28915814 100755 --- a/backup/pvc/e2e/backup_and_restore/test.sh +++ b/backup/pvc/e2e/backup_and_restore/test.sh @@ -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 \ No newline at end of file