s365b.modules.onedrive.module ============================= .. py:module:: s365b.modules.onedrive.module .. autoapi-nested-parse:: The OneDrive for Business backup module. Each user's drive is one protected object. A backup runs the drive's delta query: the first run lists every file, later runs only what changed. File content is streamed from Graph straight into the repository, so a file's size does not matter. Delta responses carry no folder paths (``parentReference.path`` is left out, and renaming a folder does not report what is inside it), so the sync state keeps every folder's name and parent, and paths are built from it. A renamed or moved folder is a :class:`~s365b.modules.sdk.GroupChange` for it and each folder below it. Delta is not a history of operations: it gives each item's latest state, in no promised order. So a deleted folder is only noted at first; when the whole round of pages is in, it is deleted with the folders still below it then (a folder moved out of it meanwhile survives). A file or folder whose parent is not known yet has its parent's chain read, so its path is never cut short. Downloaded content is checked against the size and QuickXorHash the delta gave; a file that changed while it was read fails the drive's run, which the next run reads again from the last checkpoint. The state, for a drive:: {"drive_id": "...", "root": "", "folders": {"": ["", ""], ...}, "deleting": ["", ...], "delta": "", "next": "", "resync": true} Attributes ---------- .. autoapisummary:: s365b.modules.onedrive.module.READ_PERMISSIONS s365b.modules.onedrive.module.RESTORE_PERMISSIONS s365b.modules.onedrive.module.ITEM_TYPE s365b.modules.onedrive.module.PAGE s365b.modules.onedrive.module.NO_DRIVE s365b.modules.onedrive.module.Folders Classes ------- .. autoapisummary:: s365b.modules.onedrive.module.OneDriveConfig s365b.modules.onedrive.module.OneDriveModule Functions --------- .. autoapisummary:: s365b.modules.onedrive.module.path_of s365b.modules.onedrive.module.below s365b.modules.onedrive.module.file_metadata Module Contents --------------- .. py:data:: READ_PERMISSIONS .. py:data:: RESTORE_PERMISSIONS .. py:data:: ITEM_TYPE :value: 'file' .. py:data:: PAGE .. py:data:: NO_DRIVE :value: ('itemNotFound', 'ResourceNotFound', 'MysiteNotFound', 'notFound') .. py:data:: Folders .. py:class:: OneDriveConfig Bases: :py:obj:`pydantic.BaseModel` OneDrive module settings. .. py:attribute:: include_disabled_users :type: bool .. py:function:: path_of(folders: Folders, root: str, fid: str) -> str The path of a folder, from the drive's root ("" for the root). :param folders: Known folders. :param root: The root item's ID. :param fid: The folder. :returns: Folder names joined with ``/``; an unknown parent ends the path. .. py:function:: below(folders: Folders, fid: str) -> list[str] A folder and every folder inside it, outermost first. :param folders: Known folders. :param fid: The folder. :returns: Folder IDs. .. py:function:: file_metadata(item: dict[str, Any], parent: str) -> dict[str, Any] Pick the fields shown and compared for a file. :param item: The drive item from Graph. :param parent: Its folder's ID. :returns: Metadata for the item version. .. py:class:: OneDriveModule Bases: :py:obj:`s365b.modules.sdk.BackupModule` Backs up the files in users' OneDrive for Business drives. .. py:attribute:: id :type: ClassVar[str] :value: 'onedrive' .. py:attribute:: display_name :type: ClassVar[str] :value: 'OneDrive' .. py:attribute:: description :type: ClassVar[str] :value: "Files and folders in each user's OneDrive for Business." .. py:attribute:: version :type: ClassVar[str] :value: '1.0.0' .. py:attribute:: config_model :type: ClassVar[type[pydantic.BaseModel]] .. py:attribute:: object_noun :type: ClassVar[tuple[str, str]] :value: ('drive', 'drives') .. py:attribute:: parallel_objects :type: ClassVar[int] :value: 2 .. py:method:: required_permissions(config: pydantic.BaseModel, *, restore: bool) -> set[str] Return the Graph application permissions needed. :param config: Module settings. :param restore: True for the Restore app. :returns: Reading users and every drive's files; writing files to restore. .. py:method:: restore(ctx: s365b.modules.sdk.ModuleContext, request: s365b.modules.sdk.RestoreRequest) -> s365b.modules.sdk.RestoreResult :async: Upload files into a drive. See :func:`s365b.modules.onedrive.restore.restore_files` for the options. :param ctx: Module context (Restore app). :param request: Files and where to put them. :returns: The outcome. .. py:method:: item_types() -> list[s365b.modules.sdk.ItemTypeInfo] Describe the item types. :returns: Files. .. py:method:: export(config: pydantic.BaseModel, request: s365b.modules.sdk.ExportRequest) -> collections.abc.AsyncIterator[s365b.modules.sdk.ExportFile] :async: Files in their folders, for a ZIP archive. :param config: Module settings. :param request: The files. :Yields: Each file, read when it is written. :raises NotSupportedError: For a format other than ``zip``. .. py:method:: state_for_new_repository(state: s365b.modules.sdk.SyncState) -> s365b.modules.sdk.SyncState List the drive again; keep the folders, to find deletions. :param state: The state saved by the backup into the other repository. :returns: The state to start from. .. py:method:: discover(ctx: s365b.modules.sdk.ModuleContext) -> collections.abc.AsyncIterator[s365b.modules.sdk.ProtectedObject] :async: Yield every user with a OneDrive. Guests and users whose OneDrive was never set up are left out. :param ctx: Module context. :Yields: Drives, by user ID. :raises ModuleError: If users or drives cannot be read at all. .. py:method:: backup(ctx: s365b.modules.sdk.ModuleContext, obj: s365b.modules.sdk.ProtectedObject, state: s365b.modules.sdk.SyncState) -> collections.abc.AsyncIterator[s365b.modules.sdk.ItemVersion | s365b.modules.sdk.GroupChange | s365b.modules.sdk.Checkpoint] :async: Back up one drive: everything at first, then what changed. :param ctx: Module context. :param obj: The drive (its user's ID). :param state: State saved at the last checkpoint. :Yields: Files, folder changes and checkpoints. :raises ModuleError: If the drive may not be read.