1
0
mirror of https://github.com/home-assistant/core.git synced 2025-05-22 14:57:14 +00:00

36 Commits

Author SHA1 Message Date
Martin Hjelmare
5392062edd
Add backup agent retention config () 2025-04-28 09:24:23 +02:00
Erik Montnemery
05c61b7ec3
Rename BackupManager last_non_idle_event to last_action_event ()
* Rename BackupManager last_non_idle_event to last_action_event

* Update snapshots
2025-03-19 17:28:40 +01:00
Erik Montnemery
bf190a8a73
Add backup helper ()
* Add backup helper

* Add hassio to stage 1

* Apply same changes to newly merged `webdav` and `azure_storage` to fix inflight conflict

* Address comments, add tests

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2025-02-25 10:19:41 +01:00
Erik Montnemery
351e594fe4
Add flag to backup store to track backup wizard completion ()
* Add flag to backup store to track backup wizard completion

* Add comment

* Update hassio tests

* Update tests

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2025-02-24 17:14:47 +01:00
Martin Hjelmare
119b296c26
Make backup config update a callback () 2025-02-20 11:11:34 +00:00
Erik Montnemery
22c634e626
Don't allow setting backup retention to 0 days or copies ()
* Don't allow setting backup retention to 0 days or copies

* Add tests
2025-02-18 15:16:44 +01:00
Erik Montnemery
eb5036854f
Improve error handling when supervisor backups are deleted ()
* Improve error handling when supervisor backups are deleted

* Move exception definitions
2025-02-04 19:49:55 +01:00
Erik Montnemery
5629b995ce
Include extra metadata in backup WS API ()
* Include extra metadata in backup WS API

* Update onboarding backup view

* Update google_drive tests
2025-02-04 15:57:30 +01:00
Erik Montnemery
e18dc063ba
Make backup file names more user friendly ()
* Make backup file names more user friendly

* Strip backup name

* Strip backup name

* Underscores
2025-01-31 17:33:30 +01:00
Erik Montnemery
b2ec72d75f
Persist backup restore status after core restart ()
* Persist backup restore status after core restart

* Don't blow up if restore result file can't be removed

* Update tests
2025-01-29 16:58:33 +01:00
Erik Montnemery
9a687e7f94
Add support for per-backup agent encryption flag ()
* Add support for per-backup agent encryption flag

* Adjust

* Don't attempt decrypting an unprotected backup

* Address review comments

* Add some tests

* Add fixture

* Rename fixture

* Correct condition for when we should encrypt or decrypt

* Update tests in integrations

* Improve test coverage

* Fix onedrive tests

* Add test

* Improve cipher worker shutdown

* Improve test coverage

* Fix google_drive tests

* Move inner class _CipherBackupStreamer._WorkerStatus to module scope
2025-01-29 14:04:17 +01:00
Michael
8300fd2de8
Introduce unique_id to BackupAgent ()
* add unique_id to BackupAgent

* adjust tests
2025-01-28 12:06:03 +01:00
Erik Montnemery
ea9be01c7c
Indicate in WS API when scheduling additional automatic backup () 2025-01-22 18:01:46 +00:00
Erik Montnemery
fb4df00e3c
Add support for custom weekly backup schedule ()
* Add support for custom weekly backup schedule

* Rename the new flag to custom_days

* Make the store change backwards compatible

* Improve comments
2025-01-21 08:27:41 +01:00
Erik Montnemery
43da828a51
Make the time for automated backups configurable ()
* Make the time for automated backups configurable

* Store time as a string, use None to indicate default time

* Don't add jitter if the time is set by user

* Include time of next automatic backup in response to backup/info

* Update tests

* Rename recurrence to state

* Include scheduled backup time in backup/config/info response

* Address review comments

* Update cloud test

* Add test for store migration

* Address review comments
2025-01-20 12:57:46 +01:00
Erik Montnemery
f36a10126c
Add WS command backup/can_decrypt_on_download ()
* Add WS command backup/can_decrypt_on_download

* Wrap errors

* Add default messages to exceptions

* Improve test coverage
2025-01-15 19:40:29 +01:00
Erik Montnemery
5afb9a5053
Validate password before restoring backup ()
* Validate password before restoring backup

* Raise specific error when password is incorrect
2024-12-20 15:43:46 +01:00
Erik Montnemery
7d04eef5c5
Reject duplicates in WS command backup/config/update ()
* Reject duplicates in WS command backup/config/update

* Add tests
2024-12-20 15:06:55 +01:00
Erik Montnemery
51d63ba508
Store automatic backup flag in backup metadata () 2024-12-18 18:30:46 +01:00
Erik Montnemery
5516f3609d
Rename strategy backup to automatic backup ()
* Rename strategy backup to automatic backup

* Update homeassistant/components/backup/config.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-12-18 17:35:11 +01:00
Erik Montnemery
8e991fc92f
Merge feature branch with backup changes to dev ()
* Reapply "Make WS command backup/generate send events" ()

This reverts commit 9b8316df3f78d136ae73c096168bd73ffebc4465.

* MVP implementation of Backup sync agents ()

* init sync agent

* add syncing

* root import

* rename list to info and add sync state

* Add base backup class

* Revert unneded change

* adjust tests

* move to kitchen_sink

* split

* move

* Adjustments

* Adjustment

* update

* Tests

* Test unknown agent

* adjust

* Adjust for different test environments

* Change /info WS to contain a dictinary

* reorder

* Add websocket command to trigger sync from the supervisor

* cleanup

* Make mypy happier

---------

Co-authored-by: Erik <erik@montnemery.com>

* Make BackupSyncMetadata model a dataclass ()

Make backup BackupSyncMetadata model a dataclass

* Rename backup sync agent to backup agent ()

* Rename sync agent module to agent

* Rename BackupSyncAgent to BackupAgent

* Fix test typo

* Rename async_get_backup_sync_agents to async_get_backup_agents

* Rename and clean up remaining sync things

* Update kitchen sink

* Apply suggestions from code review

* Update test_manager.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Add additional options to WS command backup/generate ()

* Add additional options to WS command backup/generate

* Improve test

* Improve test

* Align parameter names in backup/agents/* WS commands ()

* Allow setting password for backups ()

* Allow setting password for backups

* use is_hassio from helpers

* move it

* Fix getting psw

* Fix restoring with psw

* Address review comments

* Improve docstring

* Adjust kitchen sink

* Adjust

---------

Co-authored-by: Erik <erik@montnemery.com>

* Export relevant names from backup integration ()

* Tweak backup agent interface ()

* Tweak backup agent interface

* Adjust kitchen_sink

* Test kitchen sink backup ()

* Test agents_list_backups

* Test agents_info

* Test agents_download

* Export Backup from manager

* Test agents_upload

* Update tests after rebase

* Use backup domain

* Remove WS command backup/upload ()

* Remove WS command backup/upload

* Disable failing kitchen_sink test

* Make local backup a backup agent ()

* Make local backup a backup agent

* Adjust

* Adjust

* Adjust

* Adjust tests

* Adjust

* Adjust

* Adjust docstring

* Adjust

* Protect members of CoreLocalBackupAgent

* Remove redundant check for file

* Make the backup.create service use the first local agent

* Add BackupAgent.async_get_backup

* Fix some TODOs

* Add support for downloading backup from a remote agent

* Fix restore

* Fix test

* Adjust kitchen_sink test

* Remove unused method BackupManager.async_get_backup_path

* Re-enable kitchen sink test

* Remove BaseBackupManager.async_upload_backup

* Support restore from remote agent

* Fix review comments

* Include backup agent error in response to WS command backup/info ()

* Adjust code related to WS command backup/info ()

* Include backup agent error in response to WS command backup/details ()

* Remove LOCAL_AGENT_ID constant from backup manager ()

* Add backup config storage ()

* Add base for backup config

* Allow updating backup config

* Test loading backup config

* Add backup config update method

* Add temporary check for BackupAgent.async_remove_backup ()

* Rename backup slug to backup_id ()

* Improve backup websocket API tests ()

* Improve backup websocket API tests

* Add missing snapshot

* Fix tests leaving files behind

* Improve backup manager backup creation tests ()

* Remove class backup.backup.LocalBackup ()

* Add agent delete backup ()

* Add backup agent delete backup

* Remove agents delete websocket command

* Update docstring

Co-authored-by: Erik Montnemery <erik@montnemery.com>

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Disable core local backup agent in hassio ()

* Rename remove backup to delete backup ()

* Rename remove backup to delete backup

* Revert "backup/delete"

* Refactor BackupManager ()

* Refactor BackupManager

* Adjust

* Adjust backup creation

* Copy in executor

* Fix BackupManager.async_get_backup ()

* Fix typo in backup tests ()

* Adjust backup NewBackup class ()

* Remove class backup.BackupUploadMetadata ()

Remove class backup.BackupMetadata

* Report backup size in bytes instead of MB ()

Co-authored-by: Robert Resch <robert@resch.dev>

* Speed up CI for feature branch ()

* Speed up CI for feature branch

* adjust

* fix

* fix

* fix

* fix

* Rename remove to delete in backup websocket type ()

* Revert "Speed up CI for feature branch" ()

Revert "Speed up CI for feature branch ()"

This reverts commit 791280506d1859b1a722f5064d75bcbe48acc1c3.

* Rename class BaseBackup to AgentBackup ()

* Rename class BaseBackup to AgentBackup

* Update tests

* Speed up CI for backup feature branch ()

* Add backup platform to the hassio integration ()

* Add backup platform to the hassio integration

* Add hassio to after_dependencies of backup

* Address review comments

* Remove redundant hassio parametrization of tests

* Add tests

* Address review comments

* Bump CI cache version

* Revert "Bump CI cache version"

This reverts commit 2ab4d2b1795c953ccfc9b17c47f9df3faac83749.

* Extend backup info class AgentBackup ()

* Extend backup info class AgentBackup

* Update kitchen sink

* Update kitchen sink test

* Update kitchen sink test

* Exclude cloud and hassio from core files ()

* Remove unnecessary **kwargs from backup API ()

* Fix backup tests ()

* Freeze backup dataclasses ()

* Protect CoreLocalBackupAgent.load_backups ()

* Use backup metadata v2 in core/container backups ()

* Extend backup creation API ()

* Extend backup creation API

* Add tests

* Fix merge

* Fix merge

* Return agent errors when deleting a backup ()

* Return agent errors when deleting a backup

* Remove redundant calls to dict.keys()

* Add enum type for backup folder ()

* Add method AgentBackup.from_dict ()

* Remove WS command backup/agents/list_backups ()

* Handle backup schedule ()

* Add backup schedule handling

* Fix unrelated incorrect type annotation in test

* Clarify delay save

* Make the backup time compatible with the recorder nightly job

* Update create backup parameters

* Use typed dict for create backup parameters

* Simplify schedule state

* Group create backup parameters

* Move parameter

* Fix typo

* Use Folder model

* Handle deserialization of folders better

* Fail on attempt to include addons or folders in core backup ()

* Fix AgentBackup test ()

* Add options to WS command backup/restore ()

* Add options to WS command backup/restore

* Add tests

* Fix test

* Teach core backup to restore only database or only settings ()

* Exclude tmp_backups/*.tar from backups ()

* Add WS command backup/subscribe_events ()

* Clean up temporary directory after restoring backup ()

* Improve hassio backup agent list ()

* Include `last_automatic_backup` in reply to backup/info ()

Include last_automatic_backup in reply to backup/info

* Handle backup delete after config ()

* Handle delete after copies

* Handle delete after days

* Add some test examples

* Test config_delete_after_logic

* Test config_delete_after_copies_logic

* Test more delete after days

* Add debug logs

* Always delete the oldest backup first

* Never remove the last backup

* Clean up words

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Fix after cleaning words

* Use utcnow

* Remove duplicate guard

* Simplify sorting

* Delete backups even if there are agent errors on get backups

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Rename backup delete after to backup retention ()

* Rename backup delete after to backup retention

* Tweak

* Remove length limit on `agent_ids` when configuring backup ()

Remove length limit on agent_ids when configuring backup

* Rename backup retention_config to retention ()

* Modify backup agent API to be stream oriented ()

* Modify backup agent API to be stream oriented

* Fix tests

* Adjust after code review

* Remove no longer needed pylint override

* Improve test coverage

* Change BackupAgent API to work with AsyncIterator objects

* Don't close files in the event loop

* Don't close files in the event loop

* Fix backup manager create backup log ()

* Fix debug log level ()

* Add cloud backup agent ()

* Init cloud backup sync

* Add more metadata

* Fix typo

* Adjust to base changes

* Don't raise on list if more than one backup is available

* Adjust to base branch

* Fetch always and verify on download

* Update homeassistant/components/cloud/backup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Adjust to base branch changes

* Not required anymore

* Workaround

* Fix blocking event loop

* Fix

* Add some tests

* some tests

* Add cloud backup delete functionality

* Enable check

* Fix ruff

* Use fixture

* Use iter_chunks instead

* Remove read

* Remove explicit export of read_backup

* Align with BackupAgent API changes

* Improve test coverage

* Improve error handling

* Adjust docstrings

* Catch aiohttp.ClientError bubbling up from hass_nabucasa

* Improve iteration

---------

Co-authored-by: Erik <erik@montnemery.com>
Co-authored-by: Robert Resch <robert@resch.dev>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Krisjanis Lejejs <krisjanis.lejejs@gmail.com>

* Extract file receiver from `BackupManager.async_receive_backup` to util ()

* Extract file receiver from BackupManager.async_receive_backup to util

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Make sure backup directory exists ()

* Make sure backup directory exists

* Hand off directory creation to executor

* Use mkdir's exist_ok feeature

* Organize BackupManager instance attributes ()

* Don't store received backups in a TempDir ()

* Don't store received backups in a TempDir

* Fix tests

* Make sure backup directory exists

* Address review comments

* Fix tests

* Rewrite backup manager state handling ()

* Rewrite backup manager state handling

* Address review comments

* Modify backup reader/writer API to be stream oriented ()

* Internalize backup tasks ()

* Internalize backup tasks

* Update test after rebase

* Handle backup error during automatic backup ()

* Improve backup manager state logging ()

* Fix backup manager state when restore completes ()

* Remove WS command backup/agents/download ()

* Add WS command backup/generate_with_stored_settings ()

* Add WS command backup/generate_with_stored_settings

* Register the new command, add tests

* Refactor local agent backup tests ()

* Refactor test_load_backups

* Refactor test loading agents

* Refactor test_delete_backup

* Refactor test_upload

* Clean up duplicate tests

* Refactor backup manager receive tests ()

* Refactor backup manager receive tests

* Clean up

* Refactor pre and post platform tests ()

* Refactor backup pre platform test

* Refactor backup post platform test

* Bump aiohasupervisor to version 0.2.2b0 ()

* Bump aiohasupervisor to version 0.2.2b0

* Adjust tests

* Publish event when manager is idle after creating backup ()

* Handle busy backup manager when uploading backup ()

* Adjust hassio backup agent to supervisor changes ()

* Adjust hassio backup agent to supervisor changes

* Fix typo

* Refactor test for create backup with wrong parameters ()

* Refactor test not loading bad backup platforms ()

* Improve receive backup coverage ()

* Refactor initiate backup test ()

* Rename Backup to ManagerBackup ()

* Refactor backup config ()

* Refactor backup config

* Remove unnecessary condition

* Adjust tests

* Improve initiate backup test ()

* Store the time of automatic backup attempts ()

* Store the time of automatic backup attempts

* Address review comments

* Update test

* Update cloud test

* Save agent failures when creating backups ()

* Save agent failures when creating backups

* Update tests

* Store KnownBackups

* Add test

* Only clear known_backups on no error, add tests

* Address review comments

* Store known backups as a list

* Update tests

* Track all backups created with backup strategy settings ()

* Track all backups created with saved settings

* Rename

* Add explicit call to save the store

* Don't register service backup.create in HassOS installations ()

* Revert changes to action service backup.create ()

* Fix logic for cleaning up temporary backup file ()

* Fix logic for cleaning up temporary backup file

* Reduce scope of patch

* Fix with_strategy_settings info not sent over websocket ()

* Fix with_strategy_settings info not sent over websocket

* Fix kitchen sink tests

* Fix cloud and hassio tests

* Revert backup ci changes ()

Revert changes speeding up CI

* Fix revert of CI changes ()

---------

Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Robert Resch <robert@resch.dev>
Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
Co-authored-by: Krisjanis Lejejs <krisjanis.lejejs@gmail.com>
2024-12-11 21:49:34 +01:00
Erik Montnemery
9b8316df3f
Revert "Make WS command backup/generate send events" ()
Revert "Make WS command backup/generate send events ()"

This reverts commit 093b16c7235a0ee69d88ff102e2838a747a96692.
2024-11-25 13:52:32 +01:00
Erik Montnemery
093b16c723
Make WS command backup/generate send events ()
* Make WS command backup/generate send events

* Update backup.create service
2024-11-13 16:16:49 +01:00
Joakim Sørensen
31dcc25ba5
Add handler to restore a backup file with the backup integration ()
* Early pushout of restore handling for core/container

* Adjust after rebase

* Move logging definition, we should only do this if we go ahead with the restore

* First round

* More paths

* Add async_restore_backup to base class

* Block restore of new backup files

* manager tests

* Add websocket test

* Add testing to main

* Add coverage for missing backup file

* Catch FileNotFoundError instead

* Patch Path.read_text instead

* Remove HA_RESTORE from keep

* Use secure paths

* Fix restart test

* extend coverage

* Mock argv

* Adjustments
2024-11-01 16:25:22 +01:00
Joakim Sørensen
fb7bed2ea0
Add WS endpoint to fetch the details of a backup ()
* Add WS endpoint to fetch the details of a backup

* Shorten

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Adjust

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2024-10-15 13:00:34 +02:00
Joakim Sørensen
a14cb13194
Add BaseBackupManager as a common interface for backup managers ()
* Add BaseBackupManager as a common interface for backup managers

* Document the key

* Update homeassistant/components/backup/manager.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-10-15 12:31:12 +02:00
epenet
8bbbaae290
Use HassKey in backup ()
* Use HassKey in backup

* Use DATA_MANAGER
2024-10-04 16:01:50 +02:00
Sid
2cc916db6d
Replace pylint broad-except with Ruff BLE001 () 2024-05-07 14:00:27 +02:00
Marc Mueller
ff3a801936
Add empty line after module docstring [a-d] () 2024-03-08 14:51:32 +01:00
Joakim Sørensen
f622ddef47
Move backup/* WS commands to the backup integration ()
Revert "Revert "Move backup/* WS commands to the backup integration" ()"

This reverts commit 8f834268955966d93bbc85b2ae7e86e6da46e37f.
2024-02-27 11:56:07 -05:00
Joakim Sørensen
8f83426895
Revert "Move backup/* WS commands to the backup integration" ()
Revert "Move backup/* WS commands to the backup integration ()"

This reverts commit ec4e6c3a7435400cf1a9afdf2c84165be957f294.
2024-02-22 16:08:30 +01:00
Joakim Sørensen
ec4e6c3a74
Move backup/* WS commands to the backup integration ()
* Move backup/* WS commands to the backup integration

* Call correct command

* Use debug for logging

* Remove assertion of hass.data for setup test

* parametrize token fixture
2024-02-22 10:25:38 +01:00
epenet
5442d6af01
Improve msg type hint in websocket commands () 2022-10-18 16:41:17 +02:00
Joakim Sørensen
e58ce7ab6e
Fix returned value from backup/info WS command () 2022-03-01 21:37:51 +01:00
Joakim Sørensen
d018cbab3d
Enable strict typing for backup integration () 2022-03-01 13:16:10 +02:00
Joakim Sørensen
0ed51dae13
Add Backup integration ()
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2022-02-28 15:48:12 -08:00