s365b.jobs.restore

Restoring backed-up items into Microsoft 365.

A restore is asked for in Browse: some items, or everything in a folder (or a whole mailbox) matching what was shown, as it was at a point in time. The API records it as a queued job run (queue_restore()); a worker runs it (run_restore()) with the Restore app, and the module writes the items back. Like a backup, it shows live progress, can be stopped, is audited and ends with a notification.

An item that was deleted by the chosen time is restored from its last version before the deletion.

Attributes

Classes

RestoreScope

Which items: picked ones, or everything shown in Browse.

RestoreSpec

A restore: which items, into which object, where in it.

Chosen

An item to restore, with the version to restore.

Preview

What a restore would do.

Restorer

Runs queued restores.

Functions

choose(s, scope, at, *[, item_types, limit]) → list[Chosen]

Find the item versions a restore covers.

has_copies(version, names) → bool

Whether a version has all the extra copies a module restores from.

preview(services, scope) → Preview

Count what a restore covers, before starting it.

queue_restore(services, spec, requested_by, *[, ip]) → s365b.db.models.JobRun

Record a restore as a queued run and hand it to a worker.

protected_object(row) → s365b.modules.sdk.ProtectedObject

The SDK's view of a catalog object.

stored_item(c, obj, repo) → s365b.modules.sdk.StoredItem

A chosen version as the SDK's stored item, read from its repository.

run_restore(services, run_id) → None

Run a queued restore (the worker task's body).

Module Contents

s365b.jobs.restore.log[source]
s365b.jobs.restore.RESTORE_SUCCEEDED = 'restore_succeeded'[source]
s365b.jobs.restore.RESTORE_WARNING = 'restore_warning'[source]
s365b.jobs.restore.RESTORE_FAILED = 'restore_failed'[source]
s365b.jobs.restore.RESTORE_STOPPED = 'restore_stopped'[source]
s365b.jobs.restore.MAX_ITEMS = 10000[source]
class s365b.jobs.restore.RestoreScope[source]

Bases: pydantic.BaseModel

Which items: picked ones, or everything shown in Browse.

object_id: int[source]
at: datetime.datetime | None[source]
item_ids: list[int][source]
path: str | None[source]
subfolders: bool = True[source]
q: str[source]
include_deleted: bool = False[source]
class s365b.jobs.restore.RestoreSpec[source]

Bases: RestoreScope

A restore: which items, into which object, where in it.

target_object_id: int | None[source]
destination: Literal['original', 'folder'][source]
folder_name: str[source]
notify: bool[source]
class s365b.jobs.restore.Chosen[source]

An item to restore, with the version to restore.

item: s365b.db.models.Item[source]
version: s365b.db.models.ItemVersionRow[source]
async s365b.jobs.restore.choose(s: sqlalchemy.ext.asyncio.AsyncSession, scope: RestoreScope, at: datetime.datetime, *, item_types: set[str] | None = None, limit: int | None = None) → list[Chosen][source]

Find the item versions a restore covers.

Parameters:
  • s – Session.

  • scope – What to restore.

  • at – The point in time.

  • item_types – Only items of these types.

  • limit – Read at most this many items (to refuse too many cheaply).

Returns:

One version per item; for items deleted by then, the last version before the deletion.

s365b.jobs.restore.has_copies(version: s365b.db.models.ItemVersionRow, names: tuple[str, ...]) → bool[source]

Whether a version has all the extra copies a module restores from.

class s365b.jobs.restore.Preview[source]

Bases: pydantic.BaseModel

What a restore would do.

items: int[source]
bytes: int[source]
without_copy: int[source]
folders: int[source]
async s365b.jobs.restore.preview(services: s365b.core.services.Services, scope: RestoreScope) → Preview[source]

Count what a restore covers, before starting it.

Parameters:
  • services – Services.

  • scope – What to restore.

Returns:

Counts.

async s365b.jobs.restore.queue_restore(services: s365b.core.services.Services, spec: RestoreSpec, requested_by: str, *, ip: str | None = None) → s365b.db.models.JobRun[source]

Record a restore as a queued run and hand it to a worker.

Parameters:
  • services – Services.

  • spec – The restore.

  • requested_by – Username.

  • ip – The requester’s address, for the audit log.

Returns:

The queued run.

Raises:
  • LookupError – If an object does not exist.

  • ValueError – If the restore is not possible as asked.

class s365b.jobs.restore.Restorer(services: s365b.core.services.Services)[source]

Runs queued restores.

Parameters:

services – Process services.

progress_interval = 3.0[source]
services[source]
async run(run_id: int) → None[source]

Run a queued restore to the end. Never raises for problems inside it.

Parameters:

run_id – The queued run.

s365b.jobs.restore.protected_object(row: s365b.db.models.ProtectedObjectRow) → s365b.modules.sdk.ProtectedObject[source]

The SDK’s view of a catalog object.

s365b.jobs.restore.stored_item(c: Chosen, obj: s365b.modules.sdk.ProtectedObject, repo: s365b.storage.repository.Repository) → s365b.modules.sdk.StoredItem[source]

A chosen version as the SDK’s stored item, read from its repository.

async s365b.jobs.restore.run_restore(services: s365b.core.services.Services, run_id: int) → None[source]

Run a queued restore (the worker task’s body).

Parameters:
  • services – Services.

  • run_id – The queued run.