s365b.jobs.retention

Retention: remove backups older than a repository’s policy, reclaim space.

Point-in-time retention. With “keep restore points for N days”, every backup taken in the last N days can still be restored exactly. A version is removed only when no restore point in that window needs it:

  • it was replaced or deleted before the window started (valid_to is before the cutoff), or

  • it is a deletion marker older than the window (the item was deleted from Microsoft 365 more than N days ago).

So anything still in Microsoft 365 is always kept, however old, and items deleted from Microsoft 365 stay restorable for N days after deletion. Objects on hold are never touched.

After the catalog is pruned, blobs nothing refers to any more are deleted from the repository (Repository.compact()). That step holds the repository’s lock exclusively, so it never overlaps a backup.

Attributes

Classes

HousekeepingSettings

How long the app keeps its own records, and when retention runs.

Preview

What a retention policy would remove now.

Functions

keep_days(repo) → int | None

A repository's retention period in days; None means forever.

preview(s, repository_fk, days[, now]) → Preview

Count what a policy of days would remove from a repository now.

run_retention(services, repository_fk, *[, requested_by]) → tuple[int, bool]

Apply a repository's retention policy and reclaim space.

purge_records(services[, now]) → dict[str, int]

Delete audit log entries, alerts and run logs older than the housekeeping settings.

Module Contents

s365b.jobs.retention.log[source]
s365b.jobs.retention.DELETE_BATCH = 5000[source]
s365b.jobs.retention.RETENTION_FAILED = 'retention_failed'[source]
class s365b.jobs.retention.HousekeepingSettings[source]

Bases: s365b.core.settings_store.SettingsGroup

How long the app keeps its own records, and when retention runs.

Variables:
  • audit_log_days – Audit log entries older than this are deleted. Six years by default, a common choice for compliance programs.

  • alert_days – Alerts (events) older than this are deleted.

  • run_log_days – Job runs’ own logs older than this are deleted (the runs themselves are kept).

  • run_hour – Hour of the day (server time) when retention runs.

key = 'housekeeping'[source]
audit_log_days: int[source]
alert_days: int[source]
run_log_days: int[source]
run_hour: int[source]
s365b.jobs.retention.keep_days(repo: s365b.db.models.RepositoryConfig) → int | None[source]

A repository’s retention period in days; None means forever.

class s365b.jobs.retention.Preview[source]

What a retention policy would remove now.

Variables:
  • versions – Item versions removed.

  • items – Items removed entirely (no version left).

  • size – Logical size of the removed versions. Space actually freed is usually less: content shared with kept versions stays.

  • held_objects – Objects on hold, whose backups are kept regardless.

  • cutoff – Start of the kept window; None for “keep forever”.

versions: int = 0[source]
items: int = 0[source]
size: int = 0[source]
held_objects: int = 0[source]
cutoff: datetime.datetime | None = None[source]
async s365b.jobs.retention.preview(s: sqlalchemy.ext.asyncio.AsyncSession, repository_fk: int, days: int | None, now: datetime.datetime | None = None) → Preview[source]

Count what a policy of days would remove from a repository now.

Parameters:
  • s – Database session.

  • repository_fk – Repository.

  • days – Retention period; None for forever.

  • now – Current time.

Returns:

The counts.

s365b.jobs.retention.CATALOG_BEHIND = "No space was reclaimed: this repository holds backups this server's database does not know...[source]
async s365b.jobs.retention.run_retention(services: s365b.core.services.Services, repository_fk: int, *, requested_by: str = 'scheduler') → tuple[int, bool][source]

Apply a repository’s retention policy and reclaim space.

Parameters:
  • services – Process services.

  • repository_fk – Repository.

  • requested_by – Who started it.

Returns:

The job run ID, and whether it was skipped because a backup was writing to the repository (the caller retries later).

async s365b.jobs.retention.purge_records(services: s365b.core.services.Services, now: datetime.datetime | None = None) → dict[str, int][source]

Delete audit log entries, alerts and run logs older than the housekeeping settings.

Parameters:
  • services – Process services.

  • now – Current time.

Returns:

Rows deleted per table.