Occasionally I need to start a long running batch process on a server, such as a rake task to sync data from one system to another.
Leaving an SSH session open is not always possible, so here’s how to do it:
ssh server
screen -S peach
bundle exec rake long_running_task
Hitting ctrl-a then d will put the task in the background and you can then close the SSH session.
To reconnect to the long running task:
ssh server
screen -r peach
Note that “peach” is just a label for the screen session; it could be anything such as “long_running_task”, “elk123” or “404_cake_not_found”