0

我想知道是否有一种方便的方法来自动化 HomeAssistent (Hass.io) 备份 / snapsnots?

Web 前端只允许手动创建快照。这对配置来说很好,因为一旦你完成它就不会改变很多。

但是数据库呢?

4

2 回答 2

2

我认为最简单方便的方法是使用 HA 自动化:

automation:
  - alias: '[System] Weekly Backup Monday at 5:00'
    initial_state: on
    trigger:
      platform: time
      at: '05:00'
    condition:
      - condition: time
        weekday:
          - mon
    action:
      - service: hassio.snapshot_full
        data_template:
          name: "Automated Snapshot {{ now().strftime('%F') }}"
      - service: notify.hass_info
        data_template:
          message: "Automated Snapshot {{ now().strftime('%F') }}"

下一步,您可以通过特殊插件将备份存储到 Google Drive :

rest_command:
  google_backup:
    url: 'http://localhost:8055/gb/doBackup'
    timeout: '300'

automation:
  - alias: '[System] Weekly Backup Monday to Google at 5:30'
    initial_state: on
    trigger:
      - platform: time
        at: '05:30'
    condition:
      - condition: time
        weekday:
          - mon
    action:
      - service: rest_command.google_backup
      - service: notify.hass_info
        data:
          message: "Automatic snapshot uploaded"

于 2019-12-27T22:35:34.013 回答
0

我使用在服务器上运行的 Python 脚本并模仿POSTWeb 前端用来触发快照创建的请求。

首先,获取一个长寿命的访问令牌

通常它们用于附加组件,但它们在这里派上用场。您可以在 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())

现在您只需要找出在您的安装中创建快照的位置(例如/usr/share/hassio/backup,将其复制到云或外部驱动器中。

于 2019-11-17T18:13:54.727 回答