#548 Fix clearing /tmp dir in backup script

This commit is contained in:
Sylwia Brant 2021-04-26 15:57:13 +02:00
parent 57bb20bd41
commit 84b5499755
12 changed files with 46 additions and 502 deletions

View File

@ -17,6 +17,8 @@ echo "Running backup"
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
rm -r ${BACKUP_TMP_DIR}
[[ ! -s ${BACKUP_DIR}/${backup_number}.tar.gz ]] && echo "backup file '${BACKUP_DIR}/${backup_number}.tar.gz' is empty" && exit 1;
echo Done

View File

@ -0,0 +1,36 @@
#!/bin/bash
set -eo pipefail
[[ "${DEBUG}" ]] && set -x
# set current working directory to the directory of the script
cd "$(dirname "$0")"
docker_image=$1
if ! docker inspect ${docker_image} &> /dev/null; then
echo "Image '${docker_image}' does not exists"
false
fi
JENKINS_HOME="$(pwd)/jenkins_home"
BACKUP_DIR="$(pwd)/backup"
mkdir -p ${BACKUP_DIR}
# Create an instance of the container under testing
cid="$(docker run -e JENKINS_HOME=${JENKINS_HOME} -v ${JENKINS_HOME}:${JENKINS_HOME}:ro -e BACKUP_DIR=${BACKUP_DIR} -v ${BACKUP_DIR}:${BACKUP_DIR}:rw -d ${docker_image})"
echo "Docker container ID '${cid}'"
# Remove test directory and container afterwards
trap "docker rm -vf $cid > /dev/null;rm -rf ${BACKUP_DIR}" EXIT
backup_number=1
docker exec ${cid} /home/user/bin/backup.sh ${backup_number}
[ "$(docker exec ${cid} ls /tmp | grep 'tmp')" ] && echo "tmp directory not empty" && exit 1;
backup_file="${BACKUP_DIR}/${backup_number}.tar.gz"
[[ ! -f ${backup_file} ]] && echo "Backup file ${backup_file} not found" && exit 1;
echo "tmp directory empty, backup in backup directory present"
echo PASS

View File

@ -78,7 +78,7 @@ jenkins:
# version: 0.15
basePlugins:
- name: kubernetes
version: "1.28.6"
version: "1.29.2"
- name: workflow-job
version: "2.40"
- name: workflow-aggregator
@ -88,7 +88,7 @@ jenkins:
- name: job-dsl
version: "1.77"
- name: configuration-as-code
version: "1.46"
version: "1.47"
- name: kubernetes-credentials-provider
version: "0.15"

503
go.sum

File diff suppressed because it is too large Load Diff