68

How can I pause an rsync that's running?

First time I did Ctrl+C to kill it and used the -P flag to run again. Is this prone to corrupt the current file transfer?

Second time I simply put MacOS to sleep (by closing the lid). Looking at the running process I can see 2 (not sure why) with a status of 'S'.

Tried using

kill -SIGCONT

to resume the process, but it has no effect.

4 Answers 4

86

You can pause any program by sending it a TSTP (polite) or STOP (forcible) signal. On the terminal you've run rsync in, pressing Ctrl+Z sends TSTP. Resume with the fg or bg command in the terminal or a CONT signal.

It is safe to kill an rsync process and run the whole thing again; it will continue where it left off. It may be a little inefficient, particularly if you haven't passed --partial (included in -P), because rsync will check all files again and process the file it was interrupted on from scratch.

There may be unusual combinations of options that will lead to some files not being synchronized properly, maybe --inplace with something else, but I think no single option will cause this.

If you disconnect your laptop and reconnect it somewhere else, it may get a different IP address. Then the TCP connection used by rsync would be severed, so you'd have to kill it and start again. This can also happen if you suspend your laptop and the TCP connection times out. The timeout will eventually filter out to the application level, but it can take a while. It's safe to press Ctrl+C and run rsync again.

4
  • 1
    Actually killing rsync -avh simply loose the current file being copied, if the file is large you've lost quite a lot of time. Maybe Ctrl+z moving the temporary file (start with a dot) and then Ctrl-C rsync might be a better solution.
    – malat
    Commented Oct 1, 2014 at 8:49
  • Thanks for such a detailed explanation. To clarify: ctrl+z to pause, fg to resume, bg to stop.
    – Praesagus
    Commented Oct 30, 2015 at 16:20
  • 4
    @Praesagus bg to put process to the background, not to stop. Commented Jul 3, 2016 at 19:14
  • 1
    --partial is what I needed. I'm trying to copy 21GB of data, and among these I have a 6.6GB file. The problem is the network kills my connection after a few GB of data transfer, for which --partial is exactly what I need.
    – adentinger
    Commented Nov 28, 2018 at 18:13
29

Ctrl+Z to suspend, and:

$ fg

to continue, use

$ jobs

to see suspended jobs; bg [number] to background them; fg [number] to foreground it.

4
  • 2
    Ctrl+S only suspends scrolling output, not the underlying program (unless it gets blocked waiting for the terminal to accept its output), and only if you haven't disabled it. Commented Jan 16, 2011 at 13:31
  • 1
    With the current 'S' status it doesn't resume. Is it safe to kill it using Ctrl+C and run rsync again? What other options do I have? Will have that in mind next time though, thanks.
    – qnoid
    Commented Jan 16, 2011 at 13:32
  • 1
    Also note that Ctrl-Z to suspend a process is likely, after some time, to result in the timeout of any TCP network connections which were established by that program. Thus leaving an rsync suspended for more than a few minutes will very likely cause it to quit abruptly with an error message when you put it back in the foreground and it finds that its opened sockets are returning errors from reads and writes.
    – Jim Dennis
    Commented Jan 17, 2011 at 14:18
  • In my experience it is not wise to use Ctrl-Z to suspend an ongoing rsync command because (modern versions of) rsync spawn 2 worked children that do the actual work: one for getting data from the source, one for writing it to/on the destination. Those children do not necessarily get suspended, or unsuspended after you do fg. In any case I always had to abort the operation the times I tried to use (or accidentally used) Ctrl-Z.
    – RJVB
    Commented Oct 6, 2023 at 12:12
9

People here have mentioned using the --partial flag works, it needs to be mentioned however that it only resumes when the --append or --append-verify flag is used when resuming.

--partial creates a hidden file of the file that has not finished the sync process, the file is kept when you interrupt syncing. It continues to complete the file when you use --append after resuming, otherwise when not using --append, the incomplete hidden file is kept and remains incomplete.

Conclusion: You can just interrupt rsync --partial using Ctrl + C if you use rsync --append when resuming

(Source: Can rsync resume after being interrupted? retrieved 5 april 2016)

4
  • so if I have used rsync --avP <source> <destination> , I have to pause it by CTRL+C and then resume just by typing rysnc --append ? Commented Feb 20, 2017 at 6:42
  • @kingmakerking yes Commented Feb 25, 2017 at 23:00
  • 1
    @kingmakerking : No. you still need the options from your first rsync, and the source and destination. To resume, you restart your previous rsync command, and add --append to the existing options.
    – mivk
    Commented Oct 10, 2018 at 8:45
  • Really old comments, sorry for bringing this up again: Will it work when I just add the --append command in general? Or will this give me issues in case there was no interrupted file from the last run?
    – mdomino
    Commented Oct 24, 2020 at 22:21
8

Run rsync with the --partial flag. It will then keep partial transfers and resume partial files when started.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .