1

What am I doing wrong here?

I Log into the first server (using putty) and run the following query:

sh -c 'nohup mysqldump -hxxx -Pxxx -uxxx -pxxx --dump-slave --include-master-host-port --apply-slave-statements -f -q -A -E -R | mysql -hxxxx -Pxxxx -uxxxx -pxxxx' &

If I look on the two databases I can see the MySQLDump is running on the first, and being imported on the second.

But the instance I close my Putty session, (or it times out) the mysqldump stops running. I thought that using nohup was supposed to keep it running??

As it's going to take apx 8 hours to run, I can't be sitting there looking at Putty for 8 hrs to stop it timing out.

  • @RuiFRibeiro there is a pipeline in that command, so you do need to wrap it in sh -c'' to keep the pipeline running. And you can't run nohup mysqldump | nohup mysql since nohup replaces STDIN and STDOUT for commands it runs. – Dmitry Grigoryev Nov 17 '15 at 13:44
2

Since you run the shell without nohup, it receives the SIGHUP signal when you close the session, and sends it to all processes in the pipeline. Since the second mysql command is, again, run without nohup, it termitates and sends SIGPIPE to nohup mysqldump, which in turn terminates.

Try

nohup sh -c 'mysqldump -hxxx -Pxxx -uxxx -pxxx --dump-slave --include-master-host-port --apply-slave-statements -f -q -A -E -R | mysql -hxxxx -Pxxxx -uxxxx -pxxxx' &
  • cheers, it seems I beat you to it by several months, but then forgot. I like the explanation though, it makes sense now. – IGGt Nov 17 '15 at 13:36
1

Somehow, and I'll admit I'm not entirely sure how myself, the nohup isn't protecting the correct bits. Fortunately, there is a solution - start this process inside a screen or tmux session on the first server. then you can disconnect the screen / tmux session and close your PuTTY window, and the MySQL dump / import will still be running.

  • cheers, that sounds like a good solution. (It turns out I actually asked (and answered) the same question back in March - simply put the nohup at the start of the string to protect the whole thing - I feel like such a dunce!!) – IGGt Nov 17 '15 at 13:35

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.