fix(backup): use atomic mv to create backup (#1000)
This commit is contained in:
parent
3f036bdea7
commit
25b329aa13
|
|
@ -5,7 +5,9 @@ set -eo pipefail
|
|||
[[ ! $# -eq 1 ]] && echo "Usage: $0 backup_number" && exit 1;
|
||||
[[ -z "${BACKUP_DIR}" ]] && echo "Required 'BACKUP_DIR' env not set" && exit 1;
|
||||
[[ -z "${JENKINS_HOME}" ]] && echo "Required 'JENKINS_HOME' env not set" && exit 1;
|
||||
BACKUP_TMP_DIR=$(mktemp -d)
|
||||
|
||||
# create temp dir on the same filesystem with a BACKUP_DIR to be able use atomic mv enstead of copy
|
||||
BACKUP_TMP_DIR=$(mktemp -d --tmpdir=${BACKUP_DIR})
|
||||
trap "test -d "${BACKUP_TMP_DIR}" && rm -fr "${BACKUP_TMP_DIR}"" EXIT SIGINT SIGTERM
|
||||
|
||||
backup_number=$1
|
||||
|
|
@ -23,12 +25,13 @@ tar --zstd -C "${JENKINS_HOME}" -cf "${BACKUP_TMP_DIR}/${backup_number}.tar.zstd
|
|||
|
||||
if [[ "$ret" -eq 0 ]]; then
|
||||
echo "Backup was completed without warnings"
|
||||
mv "${BACKUP_TMP_DIR}/${backup_number}.tar.zstd" "${BACKUP_DIR}/${backup_number}.tar.zstd"
|
||||
elif [[ "$ret" -eq 1 ]]; then
|
||||
echo "Backup was completed with some warnings"
|
||||
mv "${BACKUP_TMP_DIR}/${backup_number}.tar.zstd" "${BACKUP_DIR}/${backup_number}.tar.zstd"
|
||||
fi
|
||||
|
||||
# atomically create a backup file
|
||||
mv "${BACKUP_TMP_DIR}/${backup_number}.tar.zstd" "${BACKUP_DIR}/${backup_number}.tar.zstd"
|
||||
|
||||
rm -rf "${BACKUP_TMP_DIR}"
|
||||
[[ ! -s ${BACKUP_DIR}/${backup_number}.tar.zstd ]] && echo "backup file '${BACKUP_DIR}/${backup_number}.tar.zstd' is empty" && exit 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ Backup and restore is done by a container sidecar.
|
|||
|
||||
### PVC
|
||||
|
||||
#### PVC Storage Size
|
||||
|
||||
Please ensure that the size of the PVC (Persistent Volume Claim) is sufficient to accommodate `BACKUP_COUNT` + `1` backup **tar.gz** archives.
|
||||
|
||||
The additional **+1** space is necessary to facilitate the creation of backups on the same filesystem and to prevent backup file corruption during copying between different filesystems. For further details, please refer to pr [#1000](https://github.com/jenkinsci/kubernetes-operator/pull/1000).
|
||||
|
||||
#### Create PVC
|
||||
|
||||
Save to the file named pvc.yaml:
|
||||
|
|
|
|||
Loading…
Reference in New Issue