Automating Proxmox Backups with Home Assistant

Hey everyone,

I recently rebuilt my homelab as 3 devices and I wanted to share my automation that powers the automated backup system.

Hardware

  • A NUC with Proxmox Virtual Environment (PVE) that runs my HASS VM
  • A NUC that runs Proxmox Backup Server (PBS)
  • A NAS

The PBS node backs up and deduplicates the PVE containers every night, but I didn’t want to have to run it 24/7. I figured I could use the HTTP APIs of both PVE and PBS to automate the process. But how can I tie this all together into a recurring automation? The answer is Home Assistant of course :slight_smile:

The automation

  1. 03:00 - HA sends a Wake-on-LAN magic packet to PBS
  2. HA waits for the Ping binary sensor to go on
  3. HA calls the PVE REST API to start a vzdump
  4. When the job finishes, PVE fires a webhook back to HA
  5. HA calls the PBS API to shut it down

I also documented the whole build and the automation process here: Automating Proxmox Backups with Home Assistant (and on YouTube: https://www.youtube.com/watch?v=GT0eXgGsZFI).

Config

This is the YAML configuration that made this possible:

configuration.yaml

wake_on_lan:

rest_command:
  pve_start_backup:
    url: "https://<PVE_IP>:8006/api2/json/nodes/pve/vzdump"
    method: POST
    headers:
      Authorization: !secret pve_api_token
    content_type: "application/x-www-form-urlencoded"
    payload: "storage=pbs&mode=snapshot&compress=zstd&all=1"
    verify_ssl: false

  pbs_shutdown:
    url: "https://<PBS_IP>:8007/api2/json/nodes/localhost/status"
    method: POST
    headers:
      Authorization: !secret pbs_api_token
    content_type: "application/x-www-form-urlencoded"
    payload: "command=shutdown"
    verify_ssl: false

automations.yaml

- id: pbs_backup_cycle
  alias: PBS Backup Cycle
  trigger:
    - platform: time
      at: "03:00:00"
  action:
    - service: wake_on_lan.send_magic_packet
      data:
        mac: "<PBS_MAC>"

    - wait_for_trigger:
        - platform: state
          entity_id: binary_sensor.pbs_online
          to: "on"
      timeout: "00:05:00"
      continue_on_timeout: false

    - delay: "00:00:30"

    - service: rest_command.pve_start_backup

    - wait_for_trigger:
        - platform: webhook
          webhook_id: pbs_backup_complete
          local_only: true
      timeout: "02:00:00"
      continue_on_timeout: true

    - service: rest_command.pbs_shutdown

And in PVE I configured a notification target pointing at http://<HA_IP>:8123/api/webhook/pbs_backup_complete (POST, body {}) and a matcher on exact:type=vzdump, with the backup job set to notification-system.

Conclusion

It was a bit of work, but I have my whole homelab running at about ~70W in 3U, and the PBS node is only awake for about 10 minutes a night. Really happy to have found the Ping and Wake on Lan integrations.

I wonder if anyone else has used these integrations before, and I’m happy to answer any questions!

That’s very cool. I have Dell OptiPlex nodes for PVE and PBS, but they only rarely get above 30w.

So I’m wondering where your 70w is coming from. More powerful nucs?

Nice! Is that 30W for both or each? And did you do any tweaking around the C States? My main NUC draws around 30W. Most of that 70W goes to the UNAS Pro including 3 HDDs.

I fortunately don’t have a way to measure them independently anymore as all devices are hooked up to my UPS which doesn’t have monitoring per outlet.

It’s total for the two i5 8GB 128GB and a 4TB external USB drive which is idle except for a few minutes each day.

The nodes aren’t doing much either yet, HAOS, Portainer, so no tweaking.

Here, give this a shot PSA How to configure Proxmox for lower power usage