我想知道是否有一种便捷的方法来自动执行HomeAssistent(Hass.io)备份/快照?
Web前端仅允许手动创建快照。这对于配置很好,因为完成后它不会改变很多。
但是数据库呢?
我使用服务器上运行的Python脚本并模仿Web前端用来触发快照创建的POST
请求。
首先,获得一个long-lived access token。
通常它们用于附件,但是在这里很方便。您可以在Web前端的用户个人资料中获得一个,向下滚动并单击“创建令牌”。
然后使用以下脚本:
import datetime
import requests
TOKEN = 'your-long-lived-access-token'
date_string = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
url = 'http://hassio.local:8123/api/hassio/snapshots/new/full'
headers = {'authorization': ('Bearer ' + TOKEN)}
response = requests.post(url,
headers=headers,
json={"name": date_string},
timeout=600) # should be enough, check duration
# check the status code to make sure the backup worked
print(response.status_code)
print(response.text)
print(response.json())
现在,您只需要找出安装中未创建snapsnot的位置(例如/usr/share/hassio/backup
,然后将其复制到云或外部驱动器中即可。