I have this commandline in Cygwin's terminal on Windows to rsync files from Win to Linux:
/usr/bin/rsync -avh --progress --no-whole-file --partial --no-owner --no-group --no-perms --omit-dir-times --log-file=/home/Stefan-Admin/transfer_d.txt /cygdrive/d/* [email protected]:/mnt/disc_1/drive_d/. > backup_to_d_drive_log.txt
This works perfectly if run by hand in the Cygwin terminal to copy the disc to a remote Ubuntu machine.
However, placing the above in a script in Cygwin terminal, fails...
E. g.
set -e
set -x
timestart=$(date)
/usr/bin/rsync -avh --progress --no-whole-file --partial --no-owner --no-group --no-perms --omit-dir-times --log-file=/home/Stefan-Admin/transfer_d.txt /cygdrive/d/* [email protected]:/mnt/disc_1/drive_d/. > backup_to_d_drive_log.txt
in a file with rwx permissions in Cygwin e. g. called, say
do_copy.sh
causes Cygwin rsync to report it cannot find /cygdrive/d ?
This is what is shown if the script file is run via "bash -f do_copy.sh" in the Cygwin terminal:
+ /usr/bin/rsync -avh --progress --no-whole-file --partial --no-owner --no-group --no-perms --omit-dir-times --log-file=/home/Stefan-Admin/transfer_d.txt '/cygdrive/d/*' [email protected]:/mnt/disc_1/drive_d/.
rsync: [sender] link_stat "/cygdrive/d/*" 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.4dev]
I note that the rsync source specification, written as
/cygdrive/d/*
when run in bash in the Cygwin terminal, suddenly becomes
'cygdrive/d/*'
if run from a .sh script via "bash -f do_copy.sh" in the Cygwin terminal.
/cygdrive/d does exist:
$ df -mh
Filesystem Size Used Avail Use% Mounted on
D: 1.6T 606G 954G 39% /cygdrive/d
$
as proven by the fact that if the above rsync command is ran "straight" in Cygwin terminal, it DOES work...
... but if you run the exact same command in a .sh file via
$ bash -f do_copy.sh
in the Cygwin terminal, rsync suddenly cannot find /cygdrive/d anywhere.
Why is that?
How can it be fixed so that rsync can be run out of a bash script on the Cygwin terminal?
Thanks!
Stefan
Ok, the solution to this issue with running rsync inside a Cygwin BASH script, when rsync cannot find
/cygdrive/d/*
is to change the rsync statement in the BASH script file to reference as rsync source
/cygdrive/d/.
e. g. the correct, working rsync commandline to rsync from Windows to Linux from a Cygwin bash script is
/usr/bin/rsync -avh --progress --no-whole-file --partial --no-owner --no-group --no-perms --omit-dir-times --log-file=/home/Stefan-Admin/transfer_d.txt /cygdrive/d/. [email protected]:/mnt/disc_1/drive_d/. > backup_to_d_drive_log.txt
After removing the wildcard * from my commandline, I can now rsync with no problems from my Windows machine to my Linux machine from a Cygwin bash -script-.
If executing the command by hand in the Cygwin terminal, using
/usr/bin/rsync -avh --progress --no-whole-file --partial --no-owner --no-group --no-perms --omit-dir-times --log-file=/home/Stefan-Admin/transfer_d.txt /cygdrive/d/* [email protected]:/mnt/disc_1/drive_d/. > backup_to_d_drive_log.txt
still works, but the "*" -must- be replaced with "." after the "/cygdrive/d/" string if running rsync from inside a Cygwin BASH script.
Hope this helps someone.
Stefan