s365b.modules.onedrive.module¶
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 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": "<root item ID>",
"folders": {"<ID>": ["<name>", "<parent ID>"], ...},
"deleting": ["<folder ID>", ...],
"delta": "<delta link>", "next": "<next page>", "resync": true}
Attributes¶
Classes¶
OneDrive module settings. |
|
Backs up the files in users' OneDrive for Business drives. |
Functions¶
|
The path of a folder, from the drive's root ("" for the root). |
|
A folder and every folder inside it, outermost first. |
|
Pick the fields shown and compared for a file. |
Module Contents¶
- s365b.modules.onedrive.module.NO_DRIVE = ('itemNotFound', 'ResourceNotFound', 'MysiteNotFound', 'notFound')[source]¶
- class s365b.modules.onedrive.module.OneDriveConfig[source]¶
Bases:
pydantic.BaseModelOneDrive module settings.
- s365b.modules.onedrive.module.path_of(folders: Folders, root: str, fid: str) str[source]¶
The path of a folder, from the drive’s root (”” for the root).
- Parameters:
folders – Known folders.
root – The root item’s ID.
fid – The folder.
- Returns:
Folder names joined with
/; an unknown parent ends the path.
- s365b.modules.onedrive.module.below(folders: Folders, fid: str) list[str][source]¶
A folder and every folder inside it, outermost first.
- Parameters:
folders – Known folders.
fid – The folder.
- Returns:
Folder IDs.
- s365b.modules.onedrive.module.file_metadata(item: dict[str, Any], parent: str) dict[str, Any][source]¶
Pick the fields shown and compared for a file.
- Parameters:
item – The drive item from Graph.
parent – Its folder’s ID.
- Returns:
Metadata for the item version.
- class s365b.modules.onedrive.module.OneDriveModule[source]¶
Bases:
s365b.modules.sdk.BackupModuleBacks up the files in users’ OneDrive for Business drives.
- required_permissions(config: pydantic.BaseModel, *, restore: bool) set[str][source]¶
Return the Graph application permissions needed.
- Parameters:
config – Module settings.
restore – True for the Restore app.
- Returns:
Reading users and every drive’s files; writing files to restore.
- async restore(ctx: s365b.modules.sdk.ModuleContext, request: s365b.modules.sdk.RestoreRequest) s365b.modules.sdk.RestoreResult[source]¶
Upload files into a drive.
See
s365b.modules.onedrive.restore.restore_files()for the options.- Parameters:
ctx – Module context (Restore app).
request – Files and where to put them.
- Returns:
The outcome.
- item_types() list[s365b.modules.sdk.ItemTypeInfo][source]¶
Describe the item types.
- Returns:
Files.
- async export(config: pydantic.BaseModel, request: s365b.modules.sdk.ExportRequest) collections.abc.AsyncIterator[s365b.modules.sdk.ExportFile][source]¶
Files in their folders, for a ZIP archive.
- Parameters:
config – Module settings.
request – The files.
- Yields:
Each file, read when it is written.
- Raises:
NotSupportedError – For a format other than
zip.
- state_for_new_repository(state: s365b.modules.sdk.SyncState) s365b.modules.sdk.SyncState[source]¶
List the drive again; keep the folders, to find deletions.
- Parameters:
state – The state saved by the backup into the other repository.
- Returns:
The state to start from.
- async discover(ctx: s365b.modules.sdk.ModuleContext) collections.abc.AsyncIterator[s365b.modules.sdk.ProtectedObject][source]¶
Yield every user with a OneDrive.
Guests and users whose OneDrive was never set up are left out.
- Parameters:
ctx – Module context.
- Yields:
Drives, by user ID.
- Raises:
ModuleError – If users or drives cannot be read at all.
- async 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][source]¶
Back up one drive: everything at first, then what changed.
- Parameters:
ctx – Module context.
obj – The drive (its user’s ID).
state – State saved at the last checkpoint.
- Yields:
Files, folder changes and checkpoints.
- Raises:
ModuleError – If the drive may not be read.