Skip to content

Include network storage mount configurations in backups#6411

Merged
mdegat01 merged 16 commits intohome-assistant:mainfrom
ptarjan:claude/submit-external-patch-01AL1gq8p9HKozCu4K1MRDTk
Mar 26, 2026
Merged

Include network storage mount configurations in backups#6411
mdegat01 merged 16 commits intohome-assistant:mainfrom
ptarjan:claude/submit-external-patch-01AL1gq8p9HKozCu4K1MRDTk

Conversation

@ptarjan
Copy link
Copy Markdown
Contributor

@ptarjan ptarjan commented Dec 8, 2025

Proposed change

When creating backups, now stores mount configurations (CIFS/NFS shares) including server, share, credentials, and other settings. When restoring from a backup, mount configurations are automatically restored.

This fixes the issue where network storage definitions for backups were lost after restoring from a backup, requiring users to manually reconfigure their network storage mounts.

Changes:

  • Add ATTR_MOUNTS schema to backup validation
  • Add store_mounts() method to save mount configs during backup
  • Add restore_mounts() method to restore mount configs during restore
  • Add MOUNTS stage to backup/restore job stages
  • Update BackupManager to call mount backup/restore methods
  • Add tests for mount backup/restore functionality

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Ruff (ruff format supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints or add-on configuration are added/changed:

Copy link
Copy Markdown

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @claude

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant Bot marked this pull request as draft December 8, 2025 15:18
@home-assistant
Copy link
Copy Markdown

home-assistant Bot commented Dec 8, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@ptarjan ptarjan force-pushed the claude/submit-external-patch-01AL1gq8p9HKozCu4K1MRDTk branch from 404f6d2 to ec11578 Compare December 8, 2025 15:19
@ptarjan ptarjan marked this pull request as ready for review December 8, 2025 15:20
When creating backups, now stores mount configurations (CIFS/NFS shares)
including server, share, credentials, and other settings. When restoring
from a backup, mount configurations are automatically restored.

This fixes the issue where network storage definitions for backups
were lost after restoring from a backup, requiring users to manually
reconfigure their network storage mounts.

Changes:
- Add ATTR_MOUNTS schema to backup validation
- Add store_mounts() method to save mount configs during backup
- Add restore_mounts() method to restore mount configs during restore
- Add MOUNTS stage to backup/restore job stages
- Update BackupManager to call mount backup/restore methods
- Add tests for mount backup/restore functionality

Fixes home-assistant/core#148663
@ptarjan ptarjan force-pushed the claude/submit-external-patch-01AL1gq8p9HKozCu4K1MRDTk branch from ec11578 to e6778d7 Compare December 8, 2025 15:32
Copy link
Copy Markdown
Contributor

@mdegat01 mdegat01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So first of all - thank you. I am not entirely sure how this got missed but mounts should absolutely be in backups.

That being said, we're going to need to rework the approach a bit. See my comments for some of the issues. The two biggest ones are currently this will store passwords unencrypted and we should change how we're restoring mounts so it doesn't fail to restore if one happens to be down at that time.

Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/backups/validate.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft December 15, 2025 21:29
@mdegat01 mdegat01 added the new-feature A new feature label Dec 15, 2025
Copy link
Copy Markdown

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @claude

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Changes based on PR review:
- Store mount configs in encrypted mounts.tar instead of unencrypted
  backup metadata (security fix for passwords)
- Separate mount restore into config save + async activation tasks
  (mounts activate in background, failures don't block restore)
- Add replace_default_backup_mount parameter to control whether to
  overwrite existing default mount setting
- Remove unnecessary broad exception handler for default mount setter
- Simplify schema: ATTR_MOUNTS is now just a boolean flag since
  actual data is in the encrypted tar file
- Update tests to reflect new async API and return types
@ptarjan ptarjan force-pushed the claude/submit-external-patch-01AL1gq8p9HKozCu4K1MRDTk branch from 66e8f5a to f2ade15 Compare December 16, 2025 05:03
@ptarjan ptarjan marked this pull request as ready for review December 16, 2025 05:11
@home-assistant home-assistant Bot requested a review from mdegat01 December 16, 2025 05:11
ptarjan and others added 3 commits December 16, 2025 05:15
- Add bind mount handling for MEDIA and SHARE usage types in
  _activate_restored_mount() to mirror MountManager.create_mount()
- Fix double save_data() call by using needs_save flag
- Import MountUsage const for usage type checks
@ptarjan
Copy link
Copy Markdown
Contributor Author

ptarjan commented Feb 8, 2026

Passwords unencrypted | ✅ Fixed - now in encrypted mounts.tar
Restore fails if network unavailable | ✅ Fixed - async activation tasks
Overwrites default mount | ✅ Fixed - added replace_default_backup_mount param
Broad exception handler | ✅ Fixed - removed
Schema duplication | ✅ Fixed - simplified to boolean flag

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@agners
Copy link
Copy Markdown
Member

agners commented Feb 11, 2026

@ptarjan it seems tests need some updates.

Copy link
Copy Markdown
Contributor

@mdegat01 mdegat01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Couple smaller comments. Also you have a couple test failures, one with the new test and the other because test_backup_progress has to be adjusted to account for the new backup stage.

Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/backups/backup.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft February 11, 2026 22:00
Comment thread supervisor/backups/backup.py Outdated
- Catch OSError separately and check errno.EBADMSG for drive health
- Validate mounts JSON against SCHEMA_MOUNTS_CONFIG before importing
- Use mount_data[ATTR_NAME] instead of .get("name", "unknown")
- Overwrite existing mounts on restore instead of skipping
- Move restore_mount/activate logic to MountManager (no more
  protected-access in Backup)
- Drop unused replace_default_backup_mount parameter
- Fix test_backup_progress: add mounts stage to expected events
- Fix test_store_mounts: avoid create_mount which requires dbus
Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/backups/backup.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft March 3, 2026 10:13
Comment thread supervisor/backups/backup.py Outdated
- Change create_inner_tar() to create_tar() per home-assistant#6575
- Remove "r" argument from SecureTarFile (now read-only by default)
- Change warning to info for missing mounts tar (old backups won't have it)
- Narrow exception handler to (MountError, vol.Invalid, KeyError, OSError)
@ptarjan ptarjan marked this pull request as ready for review March 4, 2026 06:55
@home-assistant home-assistant Bot requested a review from agners March 4, 2026 06:55
Comment thread supervisor/backups/backup.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft March 4, 2026 09:11
@agners agners marked this pull request as ready for review March 4, 2026 09:45
@home-assistant home-assistant Bot requested a review from agners March 4, 2026 09:45
Copy link
Copy Markdown
Member

@agners agners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the piece wise review here, but I think with these changes we should really be ready to land this.

Comment thread supervisor/backups/backup.py Outdated
Comment thread supervisor/mounts/manager.py
@home-assistant home-assistant Bot marked this pull request as draft March 4, 2026 09:58
- Remove ATTR_SUPERVISOR boolean flag from backup metadata; instead
  check for physical presence of supervisor.tar (like folder backups)
- Remove has_supervisor_config property
- Always attempt supervisor config restore (tar existence check handles it)
- Add HostFeature.MOUNT check in _activate_restored_mount before
  attempting to activate mounts on systems without mount support
@ptarjan ptarjan marked this pull request as ready for review March 4, 2026 16:57
@home-assistant home-assistant Bot requested a review from agners March 4, 2026 16:57
Copy link
Copy Markdown
Member

@agners agners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a test failure still which needs addressing.

@home-assistant home-assistant Bot marked this pull request as draft March 5, 2026 17:20
Resolve merge conflicts with securetar v3 and empty password changes.
Update OSError handling to use centralized check_oserror() pattern.
Fix test_restore_supervisor_config_no_tar to create and open backup
before calling restore. Add supervisor_config stage to restore progress
test expectations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@agners agners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, but a second review makes sense since I've pushed the last commit.

@agners agners marked this pull request as ready for review March 25, 2026 16:32
@home-assistant home-assistant Bot requested a review from agners March 25, 2026 16:32
Copy link
Copy Markdown
Contributor

@mdegat01 mdegat01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks @ptarjan 👍

@mdegat01 mdegat01 merged commit 2b9c828 into home-assistant:main Mar 26, 2026
20 of 21 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restoring from backup doesn’t restore some settings

4 participants