Run rsync even not connected
Brian K. White
brian at aljex.com
Wed Apr 11 20:48:33 MDT 2012
On 4/11/2012 10:05 PM, Chris Arnold wrote:
> I hopethis hope this makes sense. How do you make rsync run even when not physically connected to the server? In other words, I run rsync from the terminal via vnc and when I log out of the connection, rsync stops running. Is there a script or something I can use?
> Sent from my iPhone
Well, vnc is already itself one way, it just depends how you have
vncserver, xvnc, and your desktop session set up and how you are
disconnecting. It's possible to disconnect from a vnc session without
closing the desktop session. In that case rsync wouldn't stop any more
than any other thing running in that session.
nohup or screen are the usual answers for this though, not just for
rsync or vnc.
If you don't care about seeing the output while it's running:
nohup someprogram options... &
The output is written to nohup.out by default so you can tail -f thatto
check ongoing progress or cat/less it later when all done.
Myself I like to use screen.
screen -S foo
That doesn't look like it did anything but it did. You are now in a
screen session named foo. You can put whatever you want for "foo" it's
just a name you make up for the session so that it's easier to recognize
and reconnect to later. So in this case you might say screen -S rsync or
screen -S rsync_targetmachine
Now just run the rsync command. no nohup, no &.
Now rsync is chugging along, press ctrl-a then d to detach from the
screen session. rsync is still running in that screen session, just you
are no longer attached to that screen session.
Now you can log out, go somewhere else, connect back from somewhere
else, get a new shell, list all screen sessions:
you'll likely only have the one you created unless it's a multiuser
system and someone else uses screen. It'll say "chris 24371.foo"
To reattach to that session:
scree -r foo
Now you'll either see the ongoing rsync, or you'll see the final summary
messages and a new shell prompt.
If rsync is still running, just ctrl-a d again.
If rsync is done and you're done with that screen session, you should
type exit at the shell prompt from within the screen session, (instead
of pressing ctrl-a d to detach) that will exit that shell and close and
destroy the screen session.
You'll be back at the parent shell and screen -ls will show no sessions.
man/google nohup and gnu screen
More information about the rsync