Skip to content

Commit fa2cada

Browse files
committed
fix(backups): keep a failed MariaDB dump listing from reading as ambiguity
The cleanup script reports several matching dumps with exit code 3, which the Job's podFailurePolicy turns into an immediate release of the Backup. curl uses 3 too (malformed URL), and under set -e a listing that failed that way left the script with the same code, so a retryable S3 error would have released the Backup with a Warning about ambiguity and left the dump behind. Assisted-by: LLM Signed-off-by: Alexey Artamonov <[email protected]>
1 parent 9902861 commit fa2cada

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎hack/mariadb-backup-cleanup-script.bats‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if [ "\$method" = DELETE ]; then
4848
exit 0
4949
fi
5050
if [ -n "\${LIST_FAIL:-}" ]; then
51-
[ -n "\$fail" ] && exit 22
51+
[ -n "\$fail" ] && exit "\${LIST_FAIL_CODE:-22}"
5252
exit 0
5353
fi
5454
if [ -n "\$token" ]; then cat "$PAGES/\$token.xml"; else cat "$PAGES/first.xml"; fi
@@ -58,7 +58,7 @@ STUB
5858
export S3_ENDPOINT=s3.example:8333 S3_TLS=true S3_BUCKET=bkt S3_PREFIX=tenant-a/db/
5959
export S3_REGION=us-east-1 AWS_ACCESS_KEY_ID=ak AWS_SECRET_ACCESS_KEY=sk
6060
export WINDOW_START=2026-11-04T10:00:00Z WINDOW_END=2026-11-04T10:05:00Z
61-
unset AWS_SESSION_TOKEN S3_CA_FILE DELETE_CODE LIST_FAIL 2>/dev/null || true
61+
unset AWS_SESSION_TOKEN S3_CA_FILE DELETE_CODE LIST_FAIL LIST_FAIL_CODE 2>/dev/null || true
6262
}
6363

6464
# page writes a ListObjectsV2 body holding the given keys under $S3_PREFIX.
@@ -182,6 +182,15 @@ deletes() {
182182
[ -z "$(deletes)" ]
183183
}
184184

185+
@test "a listing that fails with curl's own exit code 3 is not reported as ambiguity" {
186+
init_stubs
187+
page first backup.2026-11-04T10:01:00Z.gzip.sql
188+
rc=0
189+
LIST_FAIL=1 LIST_FAIL_CODE=3 run_script || rc=$?
190+
[ "$rc" -ne 0 ]
191+
[ "$rc" -ne 3 ]
192+
}
193+
185194
@test "a missing object on DELETE is success, any other error status fails" {
186195
init_stubs
187196
page first backup.2026-11-04T10:01:00Z.gzip.sql

‎internal/backupcontroller/mariadb-backup-cleanup.sh‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ list_page() {
4242
names=""
4343
token=""
4444
while :; do
45-
page=$(list_page "${token}")
45+
# curl's own exit codes include 3, which would read as ambiguity.
46+
if ! page=$(list_page "${token}"); then
47+
echo "listing s3://${S3_BUCKET}/${S3_PREFIX} failed" >&2
48+
exit 1
49+
fi
4650
fields=$(printf '%s' "${page}" | tr '<' '\n')
4751
names="${names}
4852
$(printf '%s\n' "${fields}" | sed -n 's|^Key>.*/||p; s|^Key>||p')"

0 commit comments

Comments
 (0)