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.
This commit is contained in:
parent
6fffcb6754
commit
6a69cf5c88
|
|
@ -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
|
||||
exit 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue