rsync does not recognize windows path
Asked Answered
J

1

6

I'm trying to build a docker container in windows 7 (Docker tool box with oracle VM) by running a shell script in git bash, and the script has the command with rsync like shown below:

rsync -a --exclude='*/node_modules' $PROJECT_PATH/project_name/src/ ./project_name/src

and the value for $PROJECT_PATH=/c/Users/yajnesh_rai/git

This is what I see in console:

ssh: Could not resolve hostname c: Name or service not known
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [Receiver=3.1.2]

Some online documentation says to use forward slashes for path without drive name, and I tried this way

$PROJECT_PATH=\\Users\\yajnesh_rai\\git

This makes rsync work, but fails to copy file, like shown below:

\Users\yajnesh_rai\git/project_name/src/folder_name/file_name: warning: directory does not exist.

I installed rsync on windows by following steps mentioned in this post: https://blog.tiger-workshop.com/add-rsync-to-git-bash-for-windows/

Any help to tackle the issue is appreciated!! Thanks in advance

Jerusalem answered 26/7, 2018 at 10:34 Comment(1)
found a solution?Hemia
F
7

Rsync has a problem with absolute paths in Windows

I had the exact same problem when using rsync on Windows (Windows 10 64-bit). rsync doesn't like absolute Windows paths because of the C: in the path. Therefore, you should:

Replace C: with /cygdrive/c.

 

Usage example

This is how I use rsync on Windows:

rsync -av --delete /cygdrive/c/Users/Kristof/src_folder/ /cygdrive/c/Users/Kristof/dst_folder/

Rsync synchronizes source folder C:/Users/Kristof/src_folder/ to target folder C:/Users/Kristof/dst_folder/

I use the following flags:

  • -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)

    • -r, --recursive recurse into directories
    • -l, --links copy symlinks as symlinks
    • -p, --perms preserve permissions
    • -t, --times preserve modification times
    • -g, --group preserve group
    • -o, --owner preserve owner (super-user only)
    • -D same as --devices --specials
      • --devices preserve device files (super-user only)
      • --specials preserve special files
  • -v, --verbose increase verbosity

  •         --delete delete extraneous files from dest dirs
Fourgon answered 30/1, 2020 at 13:29 Comment(3)
That is only the case if you're using cygwinDoorjamb
@IuriGuilherme: no, it also works when choco install rsync is used.Uzia
@Uzia that is because the rsync package from chocolatey is the cygwin rsync, hence I stand correctedDoorjamb

© 2022 - 2024 — McMap. All rights reserved.