Ever forgot to nohup your command? This might get you out of a hole.......



Way back in the 'good' old days when only the exp/imp utlities existed and we didn't have the new (and much improved) datapump i was caught out many a time by forgetting to put an export/import job into the background and set it running with the nohup option - so even if i logged out the session the process would still carry on. I'd either end up leaving the computer on all night (with the risk of a power cut or a netowrk outage etc) or I'd kill the job and start all over again.

At the time i don't ever remember reading a solution to this even though i did read about unix's ability to suspend certain operations by sending processes a 'stop' or 'CTRL-Z' this didn't seem to work.

Having revisited this recently it seems this is now possible (maybe it always was and i just hadn't figured it out correctly).

So anyway here is a quick demo of how you can put an already running exp command into the background and nohup it. To try and illustrate this better I'm trying to represent the fact that there are 2 sessions involved here by putting session 1's screens as left aligned and session 2's screens as right aligned. Clever huh.....

OK first up lets kick of an export (for the purpose of this test I'm just doing 1 big table). As you can see i 'forgot' to nohup and background it









Lets go to session 2 and use ps to find my exp process, i then use the kill command with the -19 switch (not -9!) - this sends the process the SIGSTOP signal which tells it to just stop what it is doing (not die, just stop what it is doing). This should be what CTRL-Z should be able to do in session 1 but it doesn't seem to work for me.





Now returning to session 1 - we see on screen that the exp processes is 'Stopped'




We can see using the jobs command the job id of the exp process (in fact it is also reported in the earlier screenshot too). Using the bg command we can then put this job in the background so the process continues and we still have our shell command available. bg is called passing in %jobid as the variable - in my case %1 as i only have one job





Now i just have to 'nohup' it - this is done in the bash shell using the disown command (which was a new one on me) - similar to the bg command it takes %jobid as the argument (no arguments disowns everything). This then removes the link to my shell but the process carries on. In other shells i think nohup -p pid may work but i've nowhere to test that.

   










And now i logout!






So what are we left with now? Lets check what session 2 now sees - the dumpfile and logfile seem to carry on growing ok - lets wait for that to stop.



OK files stopped growing lets check the content of the export log - this seems to report no errors





 
As i'm not a trusting soul i still wonder if the dumpfile is somehow corrupt in the middle and actually is useless, so lets try and load it back in and see if it looks ok. First lets create a dummy user to import the table into





OK that's created lets import the file in



So it works, after all these years! I guess the same thing will work for rman/sqlplus etc

Another useful thing to remember which may save you a lot of effort/pain at some point.

Comments

  1. I know about nohup and bg... but "disown" is a new one on me also! Thanks!

    ReplyDelete
  2. Thank you ... "disown" was a new thing to learn..!!!

    ReplyDelete
  3. Wow, really useful. I didn't knew that kill -19 command could do this... Thank you!

    ReplyDelete

Post a Comment