By using the nohup, screen, or tmux commands, you can run RSYNC in the background, effectively avoiding premature termination in situations when the terminal or SSH session is closed. Let me walk you through their application.
The nohup (no hang up) command is a Unix command that can run another command while ignoring hangup signals. The usage is straightforward; simply prefix your RSYNC command with nohup, and append an ampersand (&) to it to push the process to the background. It may look like this:
`nohup rsync -a ~/dir1 /var/backups/ &`
The standard output will be redirected to a file named nohup.out, but you can redirect it to another location if you wish.
Another way to keep RSYNC running in the background is by using the screen utility. You can start a screen session, run the RSYNC command, and then detach from the screen session. Here’s an example of how to do this:
`screen -S rsync_backup`
`rsync -a ~/dir1 /var/backups/`
Then press “Ctrl-a” and “d” to detach from the screen session. To resume the session later, use the command:
`screen -r rsync_backup`
Alternatively, you could use tmux, a terminal multiplexer, in a similar way:
`tmux new -s rsync_backup`
`rsync -a ~/dir1 /var/backups/`
To detach, press “Ctrl-b” and “d”. To reattach, use the command:
`tmux attach -t rsync_backup`
The utility you select totally depends on your requirements as well as your comfort level with the command-line interface.
Note: For any long operations like this, it is highly recommended you use the `—progress` flag with the rsync command (i.e., rsync —progress) so that you can monitor the process.
All information provided is based on the sources like “LinuxConfig.org” and “TechRepublic”.
Sources:
1. “Linux nohup command.” LinuxConfig.org, www.linuxconfig.org/linux-nohup-command.
2. Demopoulos, Bill. “How to use the Linux screen command to keep your remote processes running.” TechRepublic, www.techrepublic.com/article/how-to-use-the-linux-screen-command-to-keep-your-remote-processes-running/.
3. “Tmux.” Wikipedia, en.wikipedia.org/wiki/Tmux.