12

I am transferring a large amount of files from one computer to another using rsync. I am doing this by SSHing into the source computer and executing a command like this:

sudo rsync ssh --rsync-path="sudo rsync" source_dir user@host.com:dest_dir.

Even if I add nohup before this command, whenever I close out the terminal window from which I SSHed, the connection closes.

How can I have it so that my file transfer still continues when I close my SSH connection?

15

The reason why nohup is not helping you is because the program works with standard IO files.

Here is' an excerpt from Wiki Page for nohup:

Note - Nohupping backgrounded jobs is typically used to avoid terminating them when logging off from a remote SSH session. A different issue that often arises in this situation is that ssh is refusing to log off ("hangs"), since it refuses to lose any data from/to the background job(s). This problem can also be overcome by redirecting all three I/O streams:

nohup ./myprogram > foo.out 2> foo.err < /dev/null & Also note that a closing SSH session does not always send a HUP signal to depending processes. Among others, this depends on whether a pseudo-terminal was allocated or not.

You can use screen for that.

Just create a screen session with: screen -S rsync then, you detach your screen with CTRL+A d

And you can disconnect from SSH

  • 4
    I want to add that when performing any work which will if interrupted, eg by a lost connection be problematic, then run it in a screen session. Screen is designed to protect against accidental connection loss. You can log in remotely, start screen, start your work, and if you lose connection you can re-connect to any running screen instance. Screen has got other useful functionality - capturing the session to a log file, having multiple "screens" in a single session (saving network overhead), and multiple viewers (Classroom style). Also worth mentioning that tmux is a screen alternative. – Johan Mar 17 '13 at 8:13
4

That screen command is fine, but didn't work for my needs exactly.

This worked a lot better:

nohup rsync -va --delete ###.###.###.###:/var/www/sites/ /var/www/sites < /dev/null &
  • worked for me, just like the accepted answer, thanks – Salaros Sep 14 '18 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.