Problem to copy files in a shell command in HassOS

Hello, I am trying to run a shell script in HassOS (V5.6 64 bits). The shell script is supposed to copy files (HA snapshots) from one directory (/backup) to another directory … When I run the script in SSH, it works perfectly but when I run it in HA (via a shell_command), the directory /backup seems to be empty (???). So I developped another script to have the content (using “ls -al”) of “/”, “/config” and “/backup” (when run within HA, only the last directory is returning an empty list, the other are correct)…

Anyone has a clue why (maybe different containers…) and how to fix this (SSH the script ?) ?

Finally after a lot of research on google, I developped a shell script to copy my snapshots on my Synology NAS (to keep an “offsite” copy) by using two “mount” commands: one mounting the drive on the NAS and the other using Samba to mount a drive on the Raspberry Pi (localhost) to access the backup directory containing the snapshots file (as mentioned before: not available from HA). As RSYNC is not available neither in HA (it is working in SSH though), I added in the script the comparison of the two directories to synchronize them by deleting obsolete snapshots in the target directory, the source directory is manage by the “auto-backup” add-on… The execution of the script is controlled by HA via a shell_command… So done with a lot of work-around’s complicating the script but it is working well… So HassOS is very stable and easy to update/restore but complicating some projects sometimes… Nevertheless I will migrate my two environments from “venv” environment to HassOS…

Did you publish this script anywhere?
Thank you

@baddy-0 Here is the code (by the way this script is submitted from a “ini” script to find a work around to the 60 seconds runtime limit for shell script within home assistant… (see the code at the end):

#!/bin/bash 
#
#

echo "*************************************************"
echo "*************************************************"
echo "**                                             **"
echo "**  PROGRAM TO SYNCHRONIZE /backup ON THE NAS  **"
echo "**    (directory containing the snapshots)     **"
echo "**                                             **"
echo "*************************************************"
echo "*************************************************"

echo " "
start=`date +%s%N | cut -b1-13`
day=`date +%Y-%m-%d`
hour=`date +%H:%M:%S`
echo ">>> "$day $hour

echo " "
echo ">>> Create directory /mynas..."
echo " "

mkdir -pv /mynas

echo " "
dayi=`date +%Y-%m-%d`
houri=`date +%H:%M:%S`
echo ">>> "$dayi $houri

echo " "
echo ">>> Create directory /samba..."
echo " "

mkdir -pv /samba

echo " "
dayi=`date +%Y-%m-%d`
houri=`date +%H:%M:%S`
echo ">>> "$dayi $houri

echo " "
echo ">>> Mount NFS drive on NAS Synology to /mynas..."
echo " "

mount -v -t nfs4 192.168.2.9:/volume1/BackupHA /mynas

echo " "
dayi=`date +%Y-%m-%d`
houri=`date +%H:%M:%S`
echo ">>> "$dayi $houri

echo " "
echo ">>> Mount SAMBA local drive /backup to /samba..."
echo " "

mount -v -t cifs -o username=<my_user>,password=<my_password>,domain=WORKGROUP //192.168.2.205/backup /samba

echo " "
dayi=`date +%Y-%m-%d`
houri=`date +%H:%M:%S`
echo ">>> "$dayi $houri

echo " "
echo ">>> List of files in the source directory /samba BEFORE synchronization..."
echo " "

ls -al /samba

echo " "
echo ">>> List of files in the target directory/mynas BEFORE synchronization..."
echo " "

ls -al /mynas

echo " "
dayi=`date +%Y-%m-%d`
houri=`date +%H:%M:%S`
echo ">>> "$dayi $houri

echo " "
echo ">>> Sync the two directories (/backup and /mynas)..."
echo " "

SOURCE="/samba/"
DESTINATION="/mynas/"

cp -vu /samba/*.tar /mynas

echo " "
dayi=`date +%Y-%m-%d`
houri=`date +%H:%M:%S`
echo ">>> "$dayi $houri

echo " "
echo ">>> List of files in the target directory AFTER synchronization..."
echo " "

ls -al /mynas

echo " "
dayi=`date +%Y-%m-%d`
houri=`date +%H:%M:%S`
echo ">>> "$dayi $houri

echo " "
echo ">>> Deleting old files in the target directory..."
echo " "

HITSFILES=`find $DESTINATION -type f | sed -e 's|'$DESTINATION'\(.*\)|\1|g'`

for i in $HITSFILES; do
if [ -e $SOURCE$i ]; then
echo "Yes $SOURCE$i exists in target and source directories..."
else
echo "Nope deleting $DESTINATION$i in target directory..."
rm $DESTINATION$i
fi
done

echo " "
dayi=`date +%Y-%m-%d`
houri=`date +%H:%M:%S`
echo ">>> "$dayi $houri

echo " "
echo ">>> Dismount the NFS/Samba drives..."
echo " "

umount /mynas
umount /samba

echo " "
dayi=`date +%Y-%m-%d`
houri=`date +%H:%M:%S`
echo ">>> "$dayi $houri

echo " "
echo ">>> Remove created directory /mynas and /samba..."
echo " "

rm -r /mynas
rm -r /samba

end=`date +%s%N | cut -b1-13`

runtime=$((end-start))
runtime=$(echo "scale=3; $runtime" | bc)
day=`date +%Y-%m-%d`
hour=`date +%H:%M:%S`
echo " "
echo $day $hour"    xxxxxxxxxx> Runtime (sec) : "$runtime
echo " "
echo "******************************************************" 

exit

The ini script:

#!/bin/bash
#
#

bash /config/rsync_mynas.sh &> /config/rsync_mynas.log &