Home Assistant Unofficial Reference 2024.12.1
backup.py
Go to the documentation of this file.
1 """Backup platform for the Recorder integration."""
2 
3 from logging import getLogger
4 
5 from homeassistant.core import HomeAssistant
6 from homeassistant.exceptions import HomeAssistantError
7 
8 from .util import async_migration_in_progress, get_instance
9 
10 _LOGGER = getLogger(__name__)
11 
12 
13 async def async_pre_backup(hass: HomeAssistant) -> None:
14  """Perform operations before a backup starts."""
15  _LOGGER.info("Backup start notification, locking database for writes")
16  instance = get_instance(hass)
18  raise HomeAssistantError("Database migration in progress")
19  await instance.lock_database()
20 
21 
22 async def async_post_backup(hass: HomeAssistant) -> None:
23  """Perform operations after a backup finishes."""
24  instance = get_instance(hass)
25  _LOGGER.info("Backup end notification, releasing write lock")
26  if not instance.unlock_database():
27  raise HomeAssistantError("Could not release database write lock")
None async_post_backup(HomeAssistant hass)
Definition: backup.py:22
None async_pre_backup(HomeAssistant hass)
Definition: backup.py:13
bool async_migration_in_progress(HomeAssistant hass)
Definition: util.py:809
Recorder get_instance(HomeAssistant hass)
Definition: recorder.py:74