Skip to content
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
17 changes: 13 additions & 4 deletions src/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,24 @@ def _generate_backup_list_output(self) -> str:
backup_list.append((backup_id, "physical", backup_status))
return self._format_backup_list(backup_list)

def _list_backups_ids(self) -> List[str]:
"""Retrieve the list of backup ids."""
def _list_backups_ids(self, show_failed: bool) -> List[str]:
"""Retrieve the list of backup ids.

Args:
show_failed: whether to also return the failed backups.

Returns:
the list of previously created backups or an empty list if there is no backups
in the S3 bucket.
"""
output, _ = self._execute_command(["pgbackrest", "info", "--output=json"])
backups = json.loads(output)[0]["backup"]
return [
datetime.strftime(
datetime.strptime(backup["label"][:-1], "%Y%m%d-%H%M%S"), "%Y-%m-%dT%H:%M:%SZ"
)
for backup in backups
if show_failed or not backup["error"]
]

def _initialise_stanza(self) -> None:
Expand Down Expand Up @@ -269,7 +278,7 @@ def _on_create_backup_action(self, event) -> None:
"backup",
]
)
backup_id = self._list_backups_ids()[-1]
backup_id = self._list_backups_ids(show_failed=True)[-1]
except ExecError as e:
logger.exception(e)

Expand Down Expand Up @@ -347,7 +356,7 @@ def _on_restore_action(self, event):

# Validate the provided backup id.
logger.info("Validating provided backup-id")
if backup_id not in self._list_backups_ids():
if backup_id not in self._list_backups_ids(show_failed=False):
event.fail(f"Invalid backup-id: {backup_id}")
return

Expand Down