Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
PRUNE_BACKUPS_DAYS: 3
run: ./tests/test.simple.tar.sh

- name: Test tar prune count with latest link
run: ./tests/test.prune-count.tar.sh

- name: Test restic handling
env:
RESTIC_REPOSITORY: /tmp/dest
Expand Down
2 changes: 1 addition & 1 deletion scripts/opt/backup-loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ tar() {
}

_find_extra_backups() {
find "${DEST_DIR}" -maxdepth 1 -name "*.${backup_extension}" -exec ls -1Nt {} \+ | \
find "${DEST_DIR}" -maxdepth 1 -type f -name "*.${backup_extension}" -exec ls -1Nt {} \+ | \
tail -n +$((PRUNE_BACKUPS_COUNT + 1)) | \
tr '\n' '\0'
}
Expand Down
41 changes: 41 additions & 0 deletions tests/test.prune-count.tar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -euo pipefail

set -x

WORKDIR="$(readlink -m "$(dirname "${0}")")"

cd "${WORKDIR}/.."

TMP_DIR="$(mktemp --directory)"
trap 'sudo rm -rf "${TMP_DIR}"' EXIT

: "${SRC_DIR:=/tmp/source}"
: "${DEST_DIR:=/tmp/dest}"
: "${RCON_PATH:=/usr/bin/rcon-cli}"

export LOCAL_SRC_DIR="${TMP_DIR}/${SRC_DIR}"
export LOCAL_DEST_DIR="${TMP_DIR}/${DEST_DIR}"
export TMP_DIR

"${WORKDIR}/common.bootstrap.sh"

# The latest symlink must not take one of the PRUNE_BACKUPS_COUNT slots
for run in 1 2; do
timeout 50 docker run --rm \
--env SRC_DIR="${SRC_DIR}" \
--env DEST_DIR="${DEST_DIR}" \
--env BACKUP_INTERVAL=0 \
--env INITIAL_DELAY=0s \
--env LINK_LATEST=true \
--env PRUNE_BACKUPS_COUNT=1 \
--mount "type=bind,src=${LOCAL_SRC_DIR},dst=${SRC_DIR}" \
--mount "type=bind,src=${LOCAL_DEST_DIR},dst=${DEST_DIR}" \
--mount "type=bind,src=${TMP_DIR}/rcon-cli,dst=${RCON_PATH}" \
localhost:5000/itzg/mc-backup:latest
sleep 1
done

tree "${LOCAL_DEST_DIR}"
[ 1 -eq "$(find "${LOCAL_DEST_DIR}" -maxdepth 1 -type f -name '*.tar.gz' | wc -l)" ]
tar -tzf "${LOCAL_DEST_DIR}/latest.tar.gz" > /dev/null