Improve backup exclude filters (#141311)

* Improve backup exclude filters

* Add comment
This commit is contained in:
Erik Montnemery 2025-03-25 09:52:45 +01:00 committed by GitHub
parent 4f6daa227a
commit 36d32eaabc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 3 deletions

View File

@ -16,8 +16,8 @@ DATA_MANAGER: HassKey[BackupManager] = HassKey(DOMAIN)
LOGGER = getLogger(__package__)
EXCLUDE_FROM_BACKUP = [
"__pycache__/*",
".DS_Store",
"**/__pycache__/*",
"**/.DS_Store",
".HA_RESTORE",
"*.db-shm",
"*.log.*",

View File

@ -1726,7 +1726,9 @@ class CoreBackupReaderWriter(BackupReaderWriter):
"""Filter to filter excludes."""
for exclude in excludes:
if not path.match(exclude):
# The home assistant core configuration directory is added as "data"
# in the tar file, so we need to prefix that path to the filters.
if not path.full_match(f"data/{exclude}"):
continue
LOGGER.debug("Ignoring %s because of %s", path, exclude)
return True

View File

@ -76,6 +76,7 @@ CONFIG_DIR = {
Path("backups/not_backup"),
],
"/another_subdir": [
Path("another_subdir/.DS_Store"),
Path("another_subdir/backups"),
Path("another_subdir/tts"),
],

View File

@ -70,8 +70,10 @@ _EXPECTED_FILES = [
".storage",
"another_subdir",
"another_subdir/backups",
"another_subdir/backups/backup.tar",
"another_subdir/backups/not_backup",
"another_subdir/tts",
"another_subdir/tts/voice.mp3",
"backups",
"backups/not_backup",
"tmp_backups",