I am struggling to get the syntax correct when using rsync paths that have spaces.
I get the following error...
rsync: [sender] link_stat "/media/plex/TV" failed: No such file or directory (2)
rsync: [sender] change_dir "/home/username/Series" failed: No such file or directory (2)
rsync: [sender] link_stat "/media/username/backup/TV" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1330) [sender=3.2.3]
I have tried various combinations of brackets, quotations etc but cannot get it to work.
Below is the cut down version of my bash script which is causing the issue:
source=/media/plex
destination=/media/username/backup
sub_folders=('Action' \
'Comedy' \
'Drama' \
'Horror' \
'SciFi' \
'TV Series' \
)
array_length=${#sub_folders[@]}
rsync_cmd="/usr/local/bin/rsync"
rsync_options="-a -l --dry-run"
for (( i=0; i<${array_length}; i++ )) ; do
rsync_src="$source/${sub_folders[$i]}/"
rsync_dest="$destination/${sub_folders[$i]}"
if [ ! -d "$rsync_dest" ] ; then
mkdir -p "$rsync_dest"
fi
eval $rsync_cmd $rsync_options $rsync_src $rsync_dest
done
My OS is Ubuntu 24.04 and the file system (on the USB HDD) is ExFAT
If I echo the rsync command (instead of using eval) it shows the following...
/usr/local/bin/rsync -a -l --dry-run /media/plex/TV Series/ /media/username/backup/TV Series
If I put a backslash in the path that has spaces (i.e. 'TV\ Series') then it fixes the rsync command but breaks the mkdir command, the result is:
mkdir: cannot create directory ‘/media/username/backup/TV\\ Series’: Invalid argument
mkdir -p './TV Series'(as e.g.set -xshows) which creates a directory calledTV Series. The backslash you have in the error message looks odd. You'd get it like that with GNU coreutils mkdir if you had'TV\ Series'instead. But that shouldn't be an invalid filename either on most Unixy filesystems. What OS and filesystem are you on?/mediawhich at least hints at a removable drive. Are you sure it's an ext4? Because as far as I remember, the backslash may be invalid on FAT variants, which are also what removable drives usually have... (I didn't check if that's the correct error for that case, though.) Anyway, the script as shown shouldn't create a backslash there.