I am trying to write an automation to copy backups to usb storage mounted under Media backup.
When I run the command cp /backup/*.* /media/backup/ -u under Terminal it works ok but when running an automation with a shell command it do not work.
What am I missing?
automation
alias: Copy backup to usb
description: Copy backup to usb
triggers:
- trigger: time
at: "05:00:00"
conditions: []
actions:
- action: shell_command.copy_backups
data: {}
mode: single
Never assume that if something works in an addon, it will also work inside Homeassistant itself (and terminal is also an addon). They are all different docker containers, i.e. small virtual machines.
I can run below shell_command copy_jpg from an automation and files are copied from /media/ to the usb which is mounted under /media/backup/ so the mount should be ok.
I can not run shell_command copy_backups as the log shows below. The target /media/esphome/ is a directory under /media/ and also works if copy_jpg is used so no external mount is involved in target.
This indicates that the shell_command is forbidden to read the source directory /backup/ under HAOS.
Can anybody confirm that this is intentional or could it be a bug?
Problem solved. RobC told me on Discord that the /backup/ directory was not mounted in the HA container since it is supervisor who does the backup.
So I mounted /backup/ as a networkshare in HA using samba addon and now it works with the automation and copying to the usb.
I use it in my RV for my HA green as there is not feasible to access a cloud share.
This shell does indeed work BUT it stops after 60". So it is not a good solution for making backup copies.
Note that the shell command process will be terminated after 60 seconds, full stop. There is no option to alter this behavior, this is by design because Home Assistant is not intended to manage long-running external processes.