Automation for rsync using shell_command (Help request)

I am a newbie to HA. I am trying to use rsync to make backups of camera videos to a server hosted by another pi. I am able to use rsync in the terminal integration and it copies files over. I was able to use ‘ssh-keygen -t rsa’ to connect to the destination pi without entering a password.

I was also able to put a shell_command to use the rsync command that I was able to run successfully from the terminal integration. When I run the automation, it does call the shell_script. But it does not copy the files. I have the rsync command below.

rsync -avz --delete /config/www/ [email protected]:/PiServer/videos/

The YAML command is below:
do_rsync: rsync -avz --delete /config/www/ [email protected]:/PiServer/videos/

Any ideas? Your help is appreciated.

Try adding single quotes

do_rsync: ‘rsync -avz --delete /config/www/ [email protected]:/PiServer/videos/‘

Thank you for your response. I tried that, and did not seem to work. :frowning:

Also, the documentation does not show quotes. Shell Command - Home Assistant

Any hints in the logs?

What about adding this after —delete (edit as needed):
-e ‘ssh -p 59333 -i /YOUR_PATH/.ssh/id_rsa’

The log says that rsync is not found. “rsync: command not found”

I am able to use this in the terminal with no issues.

Shell commands run in a restricted environment. See the last section of the first post here:

Thank you. I looked through the article. I get that rsync is not available readily in HA per se. Do you have any pointers in using the rsync addon? I was able to mount the external drive to the media folder. However, I am still not able to use the rsync. Is there no workaround for this?

You need a shell_command script that will SSH into the Advanced SSH & Web Terminal add on and then run the commands from there.

Thank you! I feel like I am so close!

I tried the following automation. I am not seeing any output. Can you help me?

  alias: Test_rsync
  description: ''
  - platform: time
    at: 00:00:00
  condition: []
  - service: hassio.addon_stdin
      addon: core_ssh
      input: /bin/bash /config/
  mode: single

I also tried with no luck:

  ssh_to_terminal: ssh -p 22 [email protected] "/bin/bash /config/"

This thread helped me.

This is the SSH command I use in my script.
ssh -tt -i /config/.ssh/id_ed25519 [email protected] -p 22222 -o StrictHostKeyChecking=no

I have learned the hard way that rsync does not work in the hassio environment. For my purpose, I have resorted to mounting the remote folder onto the hassio, and then calling a shell script that will copy the files to the mounted folder. I have the camera videos stored daily on specific date format folders. I run an automation daily to copy the previous date folder to the mounted location. Let me know if anyone wants more details.

Hi - just come across this whilst trying to do something similar (rsync) - if you can post/send your script/solution it would be helpful please (and where to put it). Thanks

I have abandoned this and am using a remote file copy tool to access the Samba share on HA. Would prefer rsync but hey ho, this works and is existing tool used for other purposes rather than something new.