From 6a69cf5c88070407374e4cfe9e9e469ecad7e3b7 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Thu, 11 Jul 2019 15:56:07 -0300 Subject: [PATCH 1/4] Allow rolling backups to a limit When `BACKUP_COUNT` is specified on the backup container, a backup job will ensure we keep the newest `BACKUP_COUNT` backups to preserve space in our target volume. --- backup/pvc/bin/backup.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backup/pvc/bin/backup.sh b/backup/pvc/bin/backup.sh index 631ca5b8..fe9f9c82 100644 --- a/backup/pvc/bin/backup.sh +++ b/backup/pvc/bin/backup.sh @@ -6,6 +6,11 @@ set -eo pipefail [[ -z "${BACKUP_DIR}" ]] && echo "Required 'BACKUP_DIR' env not set" && exit 1; [[ -z "${JENKINS_HOME}" ]] && echo "Required 'JENKINS_HOME' env not set" && exit 1; +if [[ ! -z "${BACKUP_COUNT}" ]]; then + echo "Trimming to only $((BACKUP_COUNT-1)) recent backups in preparation for new backup" + ls -1t ${BACKUP_DIR} | tail -n +${BACKUP_COUNT} | xargs -I '{}' rm -f ${BACKUP_DIR}/'{}' +fi + backup_number=$1 echo "Running backup" @@ -14,4 +19,4 @@ tar -C ${JENKINS_HOME} -czf "${BACKUP_DIR}/${backup_number}.tar.gz" --exclude jo [[ ! -s ${BACKUP_DIR}/${backup_number}.tar.gz ]] && echo "backup file '${BACKUP_DIR}/${backup_number}.tar.gz' is empty" && exit 1; echo Done -exit 0 \ No newline at end of file +exit 0 From 8cf9c7ba94ee435d2fd4ff1c78a797ec27ef3aba Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Thu, 11 Jul 2019 16:03:03 -0300 Subject: [PATCH 2/4] Document BACKUP_COUNT --- docs/getting-started.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/getting-started.md b/docs/getting-started.md index 4e63cd7b..4dc6799b 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -423,6 +423,8 @@ spec: value: /backup - name: JENKINS_HOME value: /jenkins-home + - name: BACKUP_COUNT + value: "2" # keep only the 2 most recent backups image: virtuslab/jenkins-operator-backup-pvc:v0.0.3 # look at backup/pvc directory imagePullPolicy: IfNotPresent volumeMounts: From f5397ed8acd570c8d825670856a89ef1f5e44908 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Thu, 11 Jul 2019 16:05:03 -0300 Subject: [PATCH 3/4] Bump backup image version --- backup/pvc/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup/pvc/VERSION.txt b/backup/pvc/VERSION.txt index f9cece58..7df503e6 100644 --- a/backup/pvc/VERSION.txt +++ b/backup/pvc/VERSION.txt @@ -1 +1 @@ -v0.0.3 +v0.0.4 From d5c453dd1b87e6bc4451946422f2b37b02d985aa Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Thu, 11 Jul 2019 16:05:33 -0300 Subject: [PATCH 4/4] Document correct backup image version --- docs/getting-started.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 4dc6799b..93c661bf 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -425,7 +425,7 @@ spec: value: /jenkins-home - name: BACKUP_COUNT value: "2" # keep only the 2 most recent backups - image: virtuslab/jenkins-operator-backup-pvc:v0.0.3 # look at backup/pvc directory + image: virtuslab/jenkins-operator-backup-pvc:v0.0.4 # look at backup/pvc directory imagePullPolicy: IfNotPresent volumeMounts: - mountPath: /jenkins-home # Jenkins home volume