Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to do a pg_dump from one server and simultaneously restore at the other server.

The command on source server (

pg_dumpall -v  | nc  4000

The command on the target server (

nc -l 4000 | psql mydb

Now I am running this from my PC via Putty. Since this process take ~5 hours, I want to background the jobs and close the terminal windows. But I am not able to figure out how to background both commands and also exit the shell.


share|improve this question

I'd use screen. If you run each end in a screen session, you can detach it (Ctrl-d) and log out while leaving it running.

share|improve this answer

To start a process that is both backgrounded and detached form the running shell, you can do the following (using your example):

(pg_dumpall -v  | nc  4000 &)

pstree comes in handy here, for verifying that it's detached (or ps -ejH if you don't have it)

share|improve this answer

Make sure to include '-d' on your listening daemon, I've run into problems with netcat, even in listen mode, not forking because it expects stdin.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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