15

I want to sync Server1 and Server2's logs to LogServer.

For Server1:

rsync -avz -e 'ssh -p 2188' user@server1:/usr/local/servers/logs/* /usr/local/logs/

This one works, but for Server2:

rsync -avz -e 'ssh -p 2188' user@server2:/usr/local/servers/logs/* /usr/local/logs/

It fails:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: no such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: no such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: no such file or directory
rsync: getcwd(): No such file or directory (2)
rsync error: errors selecting input/output files, dirs (code 3) at util.c(992) [sender=3.0.6]
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [receiver=3.0.6]

Both Server1 and Server2 is hosted on Amazon with the same version of rsync.

I am quite sure that every directory in the command is exists. How can I solve this problem?

UPDATE: I have tried ssh -p 2188 user@server2 pwd, and it doesn't work:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: no such file or directory

job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: no such file or directory

Screenshot

enter image description here

WoooHaaaa
  • 1,605
  • 4
  • 15
  • 13
  • 1
    What user are you using for rsync? I've seen that error when the current user doesn't have permissions to access the directory structure. – Sobrique Apr 28 '14 at 11:09
  • 1
    Or when the user's home directory doesn't exist on the server. – Jenny D Apr 28 '14 at 11:10
  • Current user have read permission to those logs and home directory is exist. – WoooHaaaa Apr 28 '14 at 14:42
  • Manually SSH into server2 as *user*. Does that work without any errors? If so, does `ls -R /usr/local/servers` work without any errors? – sciurus Apr 28 '14 at 17:41
  • 1
    Yes, it works without any errors ! – WoooHaaaa Apr 29 '14 at 04:16
  • does 'ssh user@server2 pwd' work too? – sendmoreinfo May 01 '14 at 11:35
  • @sendmoreinfo, this is wired, `ssh -p 2188 user@server2 pwd` doesn't work! But I can actually login server2 with ssh – WoooHaaaa May 04 '14 at 03:23
  • MrROY, could we see some evidence of that? Perhaps you can cut-and-paste in a session where you ssh to server2, then do e.g. a `pwd`, and maybe a `df -k .`? – MadHatter May 04 '14 at 05:15
  • @MadHatter, I have upload the screenshot, thanks ! – WoooHaaaa May 04 '14 at 09:26
  • The difference between launching a command with ssh and opening a shell is the init part of the shell. Have you done modifications to .bash_rc or .bash_profile ? Can you compare them between server1 and server2 ? – kranteg May 16 '14 at 14:34
  • This happened to me when I wasn't doing anything remote or over SSH. I changed my source and destination paths to be full paths, not relative to where I was when I issued the command. That fixed ti. – Joe C Sep 24 '20 at 14:24
  • Use `scp` command instead of `rsync` may be helpful for you! – Nam G VU Mar 13 '21 at 22:31

1 Answers1

50

I had the exact same issue, and my solution was something I had never thought of. In my case rsync worked fine for all the time until it stopped during some tests after changes to one of my scripts. The culprit was that my currently logged in UNIX user was in a non-existent folder that was already deleted by a script.

The getcwd(): No such file or directory (2) error message was related to $PWD, not the source, and not the destination.

Just change the folder to an existing one (e. g. cd ~) and re-run the script. Don’t forget to alter rsync paths if they aren’t already absolute.

  • 4
    I had a very similar issue today when setting up syncing between two folders and getting this message. The source and destination folders clearly existed. I checked if I might have been in a deleted folder but that wasn't the issue. But I was in the destination folder (which was a rclone mounted Google Drive). I changed my working directory to something else and the sync worked perfectly without giving an error. – inquam Feb 17 '18 at 20:30
  • 1
    I had the same issue and this solved it, much gratitude. – progonkpa Feb 21 '22 at 09:31
  • Likewise; This error is entirely unhelpful without this accompanying answer. This fact that this error doesn't more clearly point the user toward resolving the issue is... probably a bug in rsync. – MRule Sep 22 '22 at 18:19
  • Wow, it does make some sense of course, but it also didn't occur to my my rsync from and to two locations I know to exist would fail because I happened to be in a nonexistent working directory. Thanks! – Charlie Gorichanaz May 06 '23 at 06:10