Tool for backing up files from OneDrive.
The application is developed in .NET 9. Using the Entra ID, the user generates a device token, which is then cached. For proper functionality, it is necessary to have the correct permissions set in the Entra ID. This token is used to authenticate against the Microsoft Graph API, allowing access to OneDrive. Files are downloaded from OneDrive, saved to a local path, and then deleted if set to do so.
- .NET 9 SDK
- Microsoft Entra ID (Azure AD) application registration
- OneDrive account
Setting up the app registration.
The client id
must be inserted into the program settings.
For app registration you need to enable Allow public client flows, which enables Device code flow.
You need to add the following permissions to the app registration to be able to work with files on One Drive.
If there is no need to delete files, just enable
Files.Read
permissions.
No need to set up anything in OneDrive. Only the folder id
and driver cid
must be obtained from the url address. It is necessary to go to the folder from which the files will be backed up.
Copy appsettings.json
to your project root and fill in required values or set up user secrets
.
{
"EntraId": {
"ClientId": ""
},
"OneDrive": {
"Drive": "",
"FileFolder": ""
},
"BackupSettings": {
"DeleteAfterBackup": true
},
"LocalStorage": {
"Path": ""
}
}
- EntraId:ClientId - Retrieved from Azure portal.
- OneDrive:Drive - Retrieved from a url in OneDrive.
- OneDrive:FileFolder - Retrieved from a url in OneDrive.
- LocalStorage:Path - Path to local storage.
- BackupSettings:DeleteAfterBackup - Whether the files should be deleted after the backup.
Start the program.
dotnet run --project ./Src
- Auth/ – Authentication providers for Entra ID and JWT tokens.
- Configurations/ – Dependency injection and options configuration.
- GraphClients/ – Microsoft Graph API client abstractions.
- Handlers/ – File synchronization logic.
- OneDrive/ – OneDrive service integration.
- Options/ – Strongly-typed options and validators.
- Storages/ – File storage abstractions.
- App.cs – Application entry point logic.
- Program.cs – Main program bootstrap.
- 0.1
- Initial release
This project is licensed under the MIT License - see the LICENSE.md file for details.