mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-08-20 21:22:54 +00:00
fix(backup): claim the generation dir exclusively
A run starting in the same wall-clock second as its predecessor reused that predecessor's generation directory: mkdir carried exist_ok=True, so rsync --delete overwrote a finished generation before create_stamp_file refused the already-stamped directory and exited 2. The guard fired after the damage. Claim the directory exclusively instead. create_version_directory is the first filesystem action of a run, so the abort now happens with zero writes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import pathlib
|
||||
|
||||
from dirval import create_stamp_file
|
||||
|
||||
from .shell import execute_shell_command
|
||||
from .shell import BackupException, execute_shell_command
|
||||
|
||||
|
||||
def get_machine_id() -> str:
|
||||
@@ -23,7 +23,14 @@ def stamp_directory(version_dir: str) -> None:
|
||||
|
||||
def create_version_directory(versions_dir: str, backup_time: str) -> str:
|
||||
version_dir = os.path.join(versions_dir, backup_time)
|
||||
pathlib.Path(version_dir).mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
pathlib.Path(version_dir).mkdir(parents=True)
|
||||
except FileExistsError:
|
||||
raise BackupException(
|
||||
f"generation {backup_time} already exists at {version_dir}; "
|
||||
"another run claimed this second - refusing to write into it, "
|
||||
"since rsync --delete would overwrite that generation"
|
||||
) from None
|
||||
return version_dir
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user