Addon - OneDrive Backup

Some short (I hope) background

So after years as a user and fan of Home Assistant where I usually find that any feature / integration I’m looking for exists or being worked on by someone in this awesome community I finally encountered something I wanted but did not find a good solution for. Backups from Home Assistant to the cloud do exist (and are awesome) but they did not support my cloud storage provider of choice - OneDrive. While I found some suggestions on using tools like rclone this was not the seamless integration I was looking for thatproviders.

I ended up creating a OneDrive backup Addon which you can find here: lavinir/hassio-onedrive-backup (github.com).

Hopefully this can help others that were looking for a similar solution.
Any / all feedback is welcome.

Update 1: With the latest 1.4 release, it is now possible for 1 way file syncing form Home Assistant to OneDrive.

Update 2 : Version 2.0 is out introducing a dedicated WebUI along with many other improvements :slight_smile:

27 Likes

Thank you for this. Can you outline the disaster recovery scenario? I see that the backups within OneDrive are encrypted which is great. If I lose my Home Assistant installation locally what steps would I need to go through for a restore? I’m thinking download the backup manually from OneDrive but what steps would I need to do to decrypt it?

Thank you!

Yeah so I am planning for the recovery scenario to be more seamless in the next update but to restore all you need to do is copy the backup file back from OneDrive to Home Assistant under the /backup directory.
Once there Home Assistant will pick it up in the Backups menu and you can choose to restore it.
Thanks for pointing this out I will add documentation for this.

Update: Add-on now supports a “Recovery Mode” and docs have also been updated with better recovery instructions.

This is GREAT! I’ve been struggling for years with my 15GB limit of Google Drive versus my 1TB of OneDrive. Thank you!

Question - how do you force it to upload a backup to OneDrive? I got it installed, but is currently in a “stale” state and I haven’t figured out to force a backup and sync yet. Any pointers appreciated.

1 Like

You don’t need to force a backup. The Readme is pretty detailed in terms of configuration options (how often a backup is made and how many to keep in the cloud)
Anyway you can share the logs from the addon if you’re having difficulties and I can try to assist.

Yes, the Readme is GREAT.

I was asking about the ability to force a backup sync was just for testing and configuration purposes to make sure it’s working…without having to wait multiple days.

You should not have to wait at all if the backup is stale. During the next cycle it will backup / upload it to OneDrive.
If you like you can share your config and logs I can take a look.

Alright…so 3 days later, first attempt to run backup and sync failed…this is why I was wanting to test on demand to avoid waiting to find surprises. Am I missing something from a setting?

Here are my logs - looks like a timeout? My backups are 3-4GB right now… could that be why? I just changed it from 30 min to 90 min to see if that makes a difference.

11/21/2022 01:56:06 Info: Last local backup Date: 11/18/2022 01:22:18
11/21/2022 01:56:06 Info: Last online backup Date: 11/18/2022 01:22:18
11/21/2022 01:56:06 Info: Creating new backup
11/21/2022 01:56:06 Info: Starting full local backup
11/21/2022 02:26:06 Error: Failed creating new backup. System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 1800 seconds elapsing.
 ---> System.TimeoutException: The operation was canceled.
 ---> System.Threading.Tasks.TaskCanceledException: The operation was canceled.
 ---> System.IO.IOException: Unable to read data from the transport connection: Operation canceled.
 ---> System.Net.Sockets.SocketException (125): Operation canceled
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at hassio_onedrive_backup.Hass.HassioClient.CreateBackupAsync(String backupName, Boolean appendTimestamp, Boolean compressed, String password, IEnumerable`1 folders, IEnumerable`1 addons) in /src/Hass/HassioClient.cs:line 104
11/21/2022 02:26:06 Info: Online backups synced. No upload required
11/21/2022 02:26:06 Info: Interval Completed.```

I assume the 3 days is the backup interval that you set which is why there was no attempt to create another one until that period expired… Forcing would be weird as the logic to determine whether to upload a backup to OneDrive would be based on the configuration of how many backups to keep in the cloud and if they are all synced it would be weird to re-upload. To actually ‘force’ it you could just have deleted a backup from OneDrive and it would have picked it up and reuploaded.

Anyway about the solution to your actual error - This is indeed related to backup creation (not OneDrive related) that affected large backups for which an issue was previously opened. Anyway this was solved in the 1.1 release with introducing a new configuration option for setting your timeout value for backup creation if you exceed the default.

I extended the timeout and it appears to have worked. Thank you for adding that feature.

As for “forcing” maybe I’m using the wrong terminology and syncing on demand might be more accurate? The idea is to ask the add-in to sync a new backup outside of the normal window for testing or after a failure. Not suggesting re-uploads. My frame of reference is from what the Google drive backup tool does, so I was just confused as to how you ask it sync a backup after install and again after this failure.

Ok I understand, you mean a backup on-demand. I can add that to the backlog.

1 Like

Thanks for making these onedrive-backups so easy with your add-on! greatly appreciated :slight_smile:

Question: why did you force the password-protection? In essence onedrive already encrypts & protects everything, so why double-encrypt? Is it purely for the transfer?
A related feature that would be awesome: being able to sync (vs backup) certain folders to onedrive. I’m thinking e.g. the frigate section of the media-folder. Now, if I e.g. want to backup some of my frigate-recordings, many of the same recordings end up in every back-up, which quickly makes every backup very big and overflows the onedrive capacity. Is it possible to add e.g. a ‘sync’ functionality for certain folders to onedrive? (or e.g. integrate your onedrive coupling with an existing sync add-on?).

1 Like

Question: why did you force the password-protection? In essence onedrive already encrypts & protects everything, so why double-encrypt? Is it purely for the transfer?

This applies to the backup in general, whether it is stored locally or in OneDrive. “Double” encryption is not the goal, however even on OneDrive there are a lot of arguments you can make for adding additional protection to your files. Anyway I look at this as a best practice to not have a passwordless backup of Home Assistant without it causing too much of an inconvenience (I hope :))

A related feature that would be awesome: being able to sync (vs backup) certain folders to onedrive

Interesting suggestion. Added the suggestion as a poll on the official Github Repo.

1 Like

Thank you SO MUCH for this!

2 Likes

I have added OneDrive Backup to HA but it does not want to start.

I have added the ‘one drive backup’ to the sidebar but when I press it, it says one drive is not started.

I press the start button but it still doesn’t seem to start. The configuration is set to default.

Is there something I’m missing?

Any help is much appreciated:-

Regards,

Bob…

this is the backend of the log

StatusCode: 400 
ResponseBody: {"error":"invalid_grant","error_description":"AADSTS70000: The provided value for the input parameter 'device_code' is not valid.\r\nTrace ID: 98349dc4-3d28-44d0-b84d-83eee335a200\r\nCorrelation ID: 35288492-d8eb-4a43-92d1-8409cf2546d6\r\nTimestamp: 2023-04-24 15:50:37Z","error_codes":[70000],"timestamp":"2023-04-24 15:50:37Z","trace_id":"98349dc4-3d28-44d0-b84d-83eee335a200","correlation_id":"35288492-d8eb-4a43-92d1-8409cf2546d6","error_uri":"https://login.microsoftonline.com/error?code=70000"} 
Headers: Cache-Control: no-store, no-cache

Pragma: no-cache
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
P3P: CP=“DSP CUR OTPi IND OTRi ONL FIN”
client-request-id: 35288492-d8eb-4a43-92d1-8409cf2546d6
x-ms-request-id: 98349dc4-3d28-44d0-b84d-83eee335a200
x-ms-ests-server: 2.1.15175.8 - WEULR1 ProdSlices
x-ms-clitelem: 1,70000,0,
X-XSS-Protection: 0
Set-Cookie: fpc=AiddLz_cCeVHmjg1vJ_aw33uVH5VAQAAAE2c2NsOAAAA; expires=Wed, 24-May-2023 15:50:37 GMT; path=/; secure; HttpOnly; SameSite=None, x-ms-gateway-slice=estsfd; path=/; secure; samesite=none; httponly, stsservicecookie=estsfd; path=/; secure; samesite=none; httponly
Date: Mon, 24 Apr 2023 15:50:36 GMT
— End of inner exception stack trace —
at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, String additionalMessage)
at Azure.Identity.DeviceCodeCredential.GetTokenImplAsync(Boolean async, TokenRequestContext requestContext, CancellationToken cancellationToken)
at Azure.Identity.DeviceCodeCredential.GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
at hassio_onedrive_backup.Graph.GraphHelper.GetAndCacheUserTokenAsync() in /src/Graph/GraphHelper.cs:line 69
at hassio_onedrive_backup.Orchestrator.Start() in /src/Orchestrator.cs:line 73
04/24/2023 16:55:38 [28] Info: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code DS7NSN9CC to authenticate.

Please open an Issue and put in the flow / logs of your issue there.
Make sure you are using a personal onedrive account (not OneDrive for business).

Hi NirL,

Fools rush in where wisemen fear to tread :crazy_face:

see above ~ I didn’t link my OneDive to your App as per your instructions :roll_eyes:

It all seems to be working now…

Thanks for responding.

Bob…

Hi NirL,
Thanks for the addon, it is a perfect solution for creating real backups for me.
However, since a few days I am getting the notification:
Failed creating local backup. Check Addon logs for more details.
The onedrivebackup log says:
Unrecognized file found in backup folder : location backup on server.txt

I did empty the /backup folder on pi before. And now two files are in it:


The onedrivebackup Web UI shows:

So it seems the addon_5c53de3b_esphome_2023.4.1 file is giving trouble.
I don’t know where that file came from and why it is giving trouble.
And wether or not the backup is failed like showing in the notification.
Any suggestions what causes this?
And what’s the meaning of: location backup on server.txt?

Thanks in advance!