rsync-time-backup icon indicating copy to clipboard operation
rsync-time-backup copied to clipboard

Source folder with spaces

Open psmanek opened this issue 4 years ago • 3 comments

Hello,

There is a problem with source folder if it contains spaces. Ever if there are quotes "[folder name]" in command line.

rsync_tmbackup: [ERROR] Source folder "[name of the folder with spaces]" does not exist - aborting.

OS: OSX 10.14.6 bash: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)

psmanek avatar Oct 11 '19 16:10 psmanek

I ran into this problem and think I have a working solution.

first the command i am using: rsync_tmbackup.sh --rsync-append-flags -s --log-dir /home/user/.config/rsync_tmbackup -p 2222 "[email protected]:/mnt/d/test Copy" /mnt/backups/test\ Copy

note the appended -s and the use of double-quotes

and here is the 'diff original mine'

80c80
< 	fn_run_cmd "find "$DEST_FOLDER/" -maxdepth 1 -type d -name \"????-??-??-??????\" -prune | sort -r"
---
> 	fn_run_cmd "find \""$DEST_FOLDER/\"" -maxdepth 1 -type d -name \"????-??-??-??????\" -prune | sort -r"
216c217
< 		eval $1
---
> 		eval '$1'
250c251
< 	fn_run_cmd_src "test -e '$1'"
---
> 	fn_run_cmd_src "test -e \"'$1'\""
254c255
< 	fn_run_cmd_src "df -T '${1}'"
---
> 	fn_run_cmd_src "df -T \"'${1}'\""
347c348
< if [[ -z "$SRC_FOLDER" || -z "$DEST_FOLDER" ]]; then
---
> if [[ -z $SRC_FOLDER || -z $DEST_FOLDER ]]; then
372c373
< if ! fn_test_file_exists_src ${SRC_FOLDER}; then
---
> if ! fn_test_file_exists_src "$SRC_FOLDER"; then

Mostly I don't know what i'm doing so please take care when looking at what I've suggested. I slowly poked at each error messege as they came up and googled / trial and errored my way through it

i also at one point replaced single brackets with double brackets like this: if [ -z "$backup_timestamp" ]; then with if [[ -z $backup_timestamp ]]; then based on a stack overflow answer: https://stackoverflow.com/questions/3427872/whats-the-difference-between-and-in-bash?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa but i doubt that made a difference, and cluttered up the diff file for a mostly? aesthic change

this will blow up if there is a double quote " in the folder name, i saw you are already checking for a single quote '

my setup is a CentOS 8 backup server pulling files from a windows 10 box running ssh on Windows Subsystem for Linux

thanks

harywilke avatar Dec 09 '19 13:12 harywilke

There are better (as in more portable and less error prone and more compact readable code) fixes for this: when using find it is best to use find ... -print0 | xargs -0 -L1 -I{} echo "{}" to handle filenames with all sorts of cool names (including spaces ) your use of fn_run_cmd_src shows the flaw in eval $1 here https://github.com/laurent22/rsync-time-backup/blob/88db869fe7a52864e18afc7e16a971499f79e830/rsync_tmbackup.sh#L216

should be more like eval ${@:1:$#} to handle almost anything (caveat: I probably need to test some corner cases like escaped pipes and subshells and return masking, but its a huge improvement)

I wonder how #177 was fixed? 🤔 ... I should go look ...

reactive-firewall avatar Mar 19 '20 02:03 reactive-firewall

There are better (as in more portable and less error prone and more compact readable code) fixes for this: when using find it is best to use find ... -print0 | xargs -0 -L1 -I{} echo "{}" to handle filenames with all sorts of cool names (including spaces ) your use of fn_run_cmd_src shows the flaw in eval $1 here

https://github.com/laurent22/rsync-time-backup/blob/88db869fe7a52864e18afc7e16a971499f79e830/rsync_tmbackup.sh#L216

should be more like eval ${@:1:$#} to handle almost anything (caveat: I probably need to test some corner cases like escaped pipes and subshells and return masking, but its a huge improvement)

I wonder how #177 was fixed? 🤔 ... I should go look ...

Is that replacing line 216 with eval ${@:1:$#} fix the issue? I did it but still complaining source folder does not exists.

jackcctse avatar Aug 08 '20 17:08 jackcctse