Copy backup to usb with automation

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?

configuration.yaml
shell_command: 
  copy_backups: cp /backup/*.* /media/backup/ -u
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
Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/__init__.py:129
integration: Shell Command (documentation, issues)
First occurred: 10:33:41 (1 occurrences)
Last logged: 10:33:41
Error running command: `cp /backup/*.* /media/backup/ -u`, return code: 1
NoneType: None

How did you mount the usb storage?
I assume you use HAOS, which doesn’t support it out-of-the-box afaik.

I used Filebrowser addon from alexbelgium. Mount is ok under haos as terminal works ok.

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 access the usb folder from media folder under Homeassistant.

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?

shell_command: 
  copy_backups: cp /backup/*.* /media/esphome/ -u
  copy_jpg: cp /media/*.jpeg /media/backup/ -u
Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/__init__.py:129
integration: Shell Command (documentation, issues)
First occurred: 18:18:54 (2 occurrences)
Last logged: 18:22:44

Error running command: `cp /backup/*.* /media/esphome/ -u`, return code: 1
NoneType: None

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.

After much investigation, here is the almost simple solution that I found.

I formatted my 32 USB drive to ext4 and created a partition.

I installed the Samba add-on so that on my system a share is created on Media.

https://github.com/home-assistant/addons/blob/a95930e201b79c4965793fe65ccffaff5aab5cec/samba/DOCS.md

Already with udev I created an automatic recognition of the US key with a persistent name (media/usbbackup).

https://gist.github.com/eklex/c5fac345de5be9d9bc420510617c86b5

I inserted my USB stick into the USB port of my RPI5, it was recognized and mounted automatically.

Then in System/Storage I added a Network Storage on the local Samba Media/usbbackup share.

And finally in System/Backup I added a second location to the previously created Network Storage.

Then it was enough to launch a backup, it first made the backup on the system backup folder then on my USB key (usbbackup).

It worked like a charm.