enzingerm / snapborg

Synchronize snapper snapshots to a borg repository
GNU General Public License v3.0
31 stars 5 forks source link

snapper.py: Do not prevent clean-up upon empty snapshot list #22

Closed Leo3418 closed 1 year ago

Leo3418 commented 1 year ago

In Python, not [] evaluates to True. When the snapshots argument to the prevent_cleanup function is an empty list (which is not None), if not snapshots would prevent every snapshot's clean-up. The output of snapborg --dryrun backup clearly shows this:

Backing up snapshots for snapper config 'boot'...
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '1']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '77']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '245']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '413']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '437']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '461']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '485']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '509']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '533']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '557']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '558']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', '', '559']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '1']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '77']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '245']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '413']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '437']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '461']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '485']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '509']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '533']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '557']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '558']
['snapper', '-c', 'boot', '--jsonout', 'modify', '--cleanup-algorithm', 'timeline', '559']

Backup results:
OK     boot

These Snapper invocations are redundant, as only snapshots that are selected for backup need clean-up prevention during Borg execution. This commit eliminates these redundant Snapper invocations.

enzingerm commented 1 year ago

Good catch and thanks for this PR! As I see this, this would only be the case when snapborg is invoked with no new snapshots to backup, but nevertheless!