stouputils.backup.retrieve module#

get_backup_sort_key(filename: str) → str[source]#

Returns a sortable key for backup filenames.

Parameters:

filename – Backup filename or path

Returns:

Filename normalized for chronological sorting

get_all_previous_backups(
backup_folder: str,
all_before: str | None = None,
) → dict[str, dict[str, str]][source]#

Retrieves all previous backups in a folder and maps each backup to a dictionary of file paths and their hashes.

Parameters:
  • backup_folder – The folder containing previous backup zip files

  • all_before – Path to the latest backup ZIP file (If endswith “/latest.zip” or “/”, the latest backup will be used)

Returns:

file_hash}, ordered from newest to oldest

Return type:

Dictionary mapping backup file paths to dictionaries of {file_path

read_backup_hashes(
zip_path: str,
resolved_files: set[str],
) → dict[str, str][source]#

The hash of every file a backup stores that no newer backup already resolved.

Parameters:

resolved_files – Files a newer backup stored or deleted, completed in place with the ones this backup stores or deletes.

is_file_in_any_previous_backup(
file_path: str,
file_hash: str,
previous_backups: dict[str, dict[str, str]],
) → bool[source]#

Checks if a file with the same hash exists in any previous backup.

Parameters:
  • file_path – The relative path of the file

  • file_hash – The SHA-256 hash of the file

  • previous_backups – Dictionary mapping backup zip paths to their stored file hashes

Returns:

True if the file exists unchanged in any previous backup, False otherwise