Skip to content

Commit 6fb88e1

Browse files
committed
Avoid redundant borg calls
1 parent 1ba7d10 commit 6fb88e1

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ repos:
2828
- id: remove-crlf
2929
exclude_types: [binary]
3030
- repo: https://github.com/astral-sh/ruff-pre-commit
31-
rev: v0.9.10
31+
rev: v0.12.1
3232
hooks:
3333
- id: ruff-format
3434
- id: ruff
3535
args: ["--fix", "--show-fixes"]
3636
- repo: https://github.com/python-jsonschema/check-jsonschema
37-
rev: 0.31.3
37+
rev: 0.33.1
3838
hooks:
3939
- id: check-github-workflows

btrup.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,22 @@ def parse_subvolumes(output: str, prefix: str, datetime_format: str) -> dict[dat
369369

370370
def main_borg(config: Config, args: argparse.Namespace, snapshots: dict[datetime, str]):
371371
"""Main Borg part of the program."""
372-
# Not all snapshots have to be backed up.
373-
dts_prune = grandfatherson(
372+
# Get the list of snapshots to keep for borg backup
373+
dts_keep = grandfatherson(
374374
list(snapshots),
375375
config.time_origin,
376376
[(keep.interval, keep.amount) for keep in config.keeps if keep.backup],
377-
)[1]
378-
for dt_prune in dts_prune:
379-
del snapshots[dt_prune]
377+
)[0]
378+
379+
# If the latest snapshot is not in the keep list, do not run Borg.
380+
last_snapshot = max(snapshots)
381+
if max(snapshots) not in dts_keep:
382+
LOGGER.info(f"Skipping borg, snapshot not selected for backup: ({last_snapshot})")
383+
LOGGER.info(f"Most recent snapshot selected for backup: {max(dts_keep)}")
384+
return
385+
386+
# Filter snapshots, only those in keep list. (prune list is not complete.)
387+
snapshots = {dt: subvol for dt, subvol in snapshots.items() if dt in dts_keep}
380388

381389
# Backup the selected snapshots to every Borg repository.
382390
env = config.borg.env

0 commit comments

Comments
 (0)