Killing rsync softly

killrsync

Is there a way of tell rsync to stop whenever possible in a clean way? Two options:

  • tell rsync to stop transfering the current file, clean any temp file and exit;
  • or let rsync end the transfer of the current file and then stop.

By doing Ctrl + C it does stop mid-transfer and leaves the temporary files there, right?

Edit

Even if using --inplace? What would be the best course of action? I'm using rsync with --inplace and I have to go fast, how can I say “May be end with this file then quit, or quit now, but clean this file you were copying so you don't leave corrupt things (I don't care if it's removed, I can backup again later)” or something like that.

Best Answer

If you kill rsync with Ctrl+C it does stop it mid transfer but it will not keep any temporary files there unless running with the --partial option.

For those also interested in just pausing rsync, if you press Ctrl+Z it pauses the program. When you resume it by running fg or bg rsync will reiterate over the file that it didn't finish and continue downloading the rest of the files. To see all currently paused programs run jobs

About --inplace

The problem with --inplace is that it does not create a new file when updating data, it just writes to the existing one. If you press ctrl + c while running with --inplace and it is updating an existing file it will leave a half finished file without removing it. Also if you are syncing only new files and not updating existing ones then when you cut off a transfer (with ctrl + c) it will leave a half finished file that it won't remove. Just a note I would not recommend --inplace for OS files. You can really jack up some things (because they change frequently)

Related Question