Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backups: default keep=None, which keeps all previous backups #167

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
21 changes: 11 additions & 10 deletions disk_objectstore/backup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BackupManager:
def __init__(
self,
dest: str,
keep: int = 1,
keep: Optional[int] = None,
rsync_exe: Optional[str] = None,
) -> None:
self.dest = dest
Expand All @@ -60,7 +60,7 @@ def __init__(

# Validate the backup config inputs

if self.keep < 0:
if self.keep is not None and self.keep < 0:
raise ValueError(
"Input validation failed: keep variable can't be negative!"
)
Expand Down Expand Up @@ -247,14 +247,15 @@ def get_last_backup_folder(self):

def delete_old_backups(self):
"""Get all folders matching the backup pattern, and delete oldest ones."""
sorted_folders = sorted(self.get_existing_backup_folders())
to_delete = sorted_folders[: -(self.keep + 1)]
for folder in to_delete:
success = self.run_cmd(["rm", "-rf", folder])[0]
if success:
LOGGER.info("Deleted old backup: %s", folder)
else:
LOGGER.warning("Warning: couldn't delete old backup: %s", folder)
if self.keep is not None:
sorted_folders = sorted(self.get_existing_backup_folders())
to_delete = sorted_folders[: -(self.keep + 1)]
for folder in to_delete:
success = self.run_cmd(["rm", "-rf", folder])[0]
if success:
LOGGER.info("Deleted old backup: %s", folder)
else:
LOGGER.warning("Warning: couldn't delete old backup: %s", folder)

def backup_auto_folders(self, backup_func: Callable) -> None:
"""Create a backup, managing live and previous backup folders automatically
Expand Down
Loading