From 35859cd5ce7ac61f2c4aa4161f9fd4289663ad7c Mon Sep 17 00:00:00 2001 From: Paul Becotte Date: Thu, 16 Jan 2020 18:56:17 -0500 Subject: [PATCH] backups should only exclude config.xml in top level job directories, ones below that are artifacts --- backup/pvc/Dockerfile | 6 +++--- backup/pvc/bin/backup.sh | 6 +++++- .../backup_and_restore/jenkins_home/jobs/orgjob/config.xml | 0 .../jobs/orgjob/jobs/branchjob/branches/master/build | 0 .../jobs/orgjob/jobs/branchjob/branches/master/config.xml | 0 .../jenkins_home/jobs/orgjob/jobs/branchjob/config.xml | 0 .../jenkins_home/jobs/some-job/builds/1/workspace/artifact | 0 .../jenkins_home/jobs/some-job/config.xml | 0 backup/pvc/e2e/backup_and_restore/test.sh | 6 +++--- 9 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/config.xml create mode 100644 backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/jobs/branchjob/branches/master/build create mode 100644 backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/jobs/branchjob/branches/master/config.xml create mode 100644 backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/orgjob/jobs/branchjob/config.xml create mode 100644 backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/some-job/builds/1/workspace/artifact create mode 100644 backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/some-job/config.xml diff --git a/backup/pvc/Dockerfile b/backup/pvc/Dockerfile index 7109d932b..3f4ebbc57 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/bin/backup.sh b/backup/pvc/bin/backup.sh index 71a8f8e70..b8dfa98c8 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 000000000..e69de29bb 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 000000000..e69de29bb 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 000000000..e69de29bb 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 000000000..e69de29bb diff --git a/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/some-job/builds/1/workspace/artifact b/backup/pvc/e2e/backup_and_restore/jenkins_home/jobs/some-job/builds/1/workspace/artifact new file mode 100644 index 000000000..e69de29bb 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 000000000..e69de29bb diff --git a/backup/pvc/e2e/backup_and_restore/test.sh b/backup/pvc/e2e/backup_and_restore/test.sh index b392d63bc..672cb25b0 100755 --- a/backup/pvc/e2e/backup_and_restore/test.sh +++ b/backup/pvc/e2e/backup_and_restore/test.sh @@ -35,6 +35,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} -echo "Directories are the same" -echo PASS \ No newline at end of file +test $(diff --brief --recursive ${JENKINS_HOME} ${RESTORE_FOLDER} | wc -l) = 3 +echo "Directories are the same except for 2 excluded config.xml and the 1 workspace file" +echo PASS