s365b.jobs.restore ================== .. py:module:: s365b.jobs.restore .. autoapi-nested-parse:: 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 (:func:`queue_restore`); a worker runs it (:func:`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 ---------- .. autoapisummary:: s365b.jobs.restore.log s365b.jobs.restore.RESTORE_SUCCEEDED s365b.jobs.restore.RESTORE_WARNING s365b.jobs.restore.RESTORE_FAILED s365b.jobs.restore.RESTORE_STOPPED s365b.jobs.restore.MAX_ITEMS Classes ------- .. autoapisummary:: s365b.jobs.restore.RestoreScope s365b.jobs.restore.RestoreSpec s365b.jobs.restore.Chosen s365b.jobs.restore.Preview s365b.jobs.restore.Restorer Functions --------- .. autoapisummary:: s365b.jobs.restore.choose s365b.jobs.restore.has_copies s365b.jobs.restore.preview s365b.jobs.restore.queue_restore s365b.jobs.restore.protected_object s365b.jobs.restore.stored_item s365b.jobs.restore.run_restore Module Contents --------------- .. py:data:: log .. py:data:: RESTORE_SUCCEEDED :value: 'restore_succeeded' .. py:data:: RESTORE_WARNING :value: 'restore_warning' .. py:data:: RESTORE_FAILED :value: 'restore_failed' .. py:data:: RESTORE_STOPPED :value: 'restore_stopped' .. py:data:: MAX_ITEMS :value: 10000 .. py:class:: RestoreScope Bases: :py:obj:`pydantic.BaseModel` Which items: picked ones, or everything shown in Browse. .. py:attribute:: object_id :type: int .. py:attribute:: at :type: datetime.datetime | None .. py:attribute:: item_ids :type: list[int] .. py:attribute:: path :type: str | None .. py:attribute:: subfolders :type: bool :value: True .. py:attribute:: q :type: str .. py:attribute:: include_deleted :type: bool :value: False .. py:class:: RestoreSpec Bases: :py:obj:`RestoreScope` A restore: which items, into which object, where in it. .. py:attribute:: target_object_id :type: int | None .. py:attribute:: destination :type: Literal['original', 'folder'] .. py:attribute:: folder_name :type: str .. py:attribute:: notify :type: bool .. py:class:: Chosen An item to restore, with the version to restore. .. py:attribute:: item :type: s365b.db.models.Item .. py:attribute:: version :type: s365b.db.models.ItemVersionRow .. py:function:: choose(s: sqlalchemy.ext.asyncio.AsyncSession, scope: RestoreScope, at: datetime.datetime, *, item_types: set[str] | None = None, limit: int | None = None) -> list[Chosen] :async: Find the item versions a restore covers. :param s: Session. :param scope: What to restore. :param at: The point in time. :param item_types: Only items of these types. :param 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. .. py:function:: has_copies(version: s365b.db.models.ItemVersionRow, names: tuple[str, ...]) -> bool Whether a version has all the extra copies a module restores from. .. py:class:: Preview Bases: :py:obj:`pydantic.BaseModel` What a restore would do. .. py:attribute:: items :type: int .. py:attribute:: bytes :type: int .. py:attribute:: without_copy :type: int .. py:attribute:: folders :type: int .. py:function:: preview(services: s365b.core.services.Services, scope: RestoreScope) -> Preview :async: Count what a restore covers, before starting it. :param services: Services. :param scope: What to restore. :returns: Counts. .. py:function:: queue_restore(services: s365b.core.services.Services, spec: RestoreSpec, requested_by: str, *, ip: str | None = None) -> s365b.db.models.JobRun :async: Record a restore as a queued run and hand it to a worker. :param services: Services. :param spec: The restore. :param requested_by: Username. :param ip: The requester's address, for the audit log. :returns: The queued run. :raises LookupError: If an object does not exist. :raises ValueError: If the restore is not possible as asked. .. py:class:: Restorer(services: s365b.core.services.Services) Runs queued restores. :param services: Process services. .. py:attribute:: progress_interval :value: 3.0 .. py:attribute:: services .. py:method:: run(run_id: int) -> None :async: Run a queued restore to the end. Never raises for problems inside it. :param run_id: The queued run. .. py:function:: protected_object(row: s365b.db.models.ProtectedObjectRow) -> s365b.modules.sdk.ProtectedObject The SDK's view of a catalog object. .. py:function:: stored_item(c: Chosen, obj: s365b.modules.sdk.ProtectedObject, repo: s365b.storage.repository.Repository) -> s365b.modules.sdk.StoredItem A chosen version as the SDK's stored item, read from its repository. .. py:function:: run_restore(services: s365b.core.services.Services, run_id: int) -> None :async: Run a queued restore (the worker task's body). :param services: Services. :param run_id: The queued run.