How to use "nohup" with chained commands in Ubuntu
October 30, 2018 Comments
This is another note to self as I keep forgetting the syntax.
Basically I needed to use nohup (short for "no hangup") to execute a PostgreSQL database dump while connected to a remote server via SSH. The reason is to make sure the command doesn't get terminated in case I get disconnected from the server as the command could take some time to complete due to the size of the database I'm backing up.
Since it involves multiple commands chained together, I can't just do nohup command &, I have to wrap it in sh -c like this:
nohup sh -c "export PGPASSWORD=thedbpassword && pg_dump -h blahblah.us-east-1.rds.amazonaws.com -U theuser -Fc thedb -f mydb.bak" > /dev/null &