Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 08-28-2008, 06:08 AM   #1
LQ Newbie
Registered: Aug 2008
Posts: 6

Rep: Reputation: 0
Killing rsync cleanly?


Is there a way to kill rsync so than no temporal files will be left behind?

For example, when I'm transferring test.bin from one folder to another, and rsync is killed, it leaves behind a file named .test.bin.4IOU9 I want rsync to delete that file when it's killed.

Thanks for the help,

Old 08-28-2008, 10:02 AM   #2
LQ Guru
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 252Reputation: 252Reputation: 252
Well, kill it nicely then. If you're just abruptly killing it by doing a ctrl-c or the like, if the process is gone, how's it suppose to clean up after itself? I've never tried but while it's copying or running, try sending a kill -15 to the process and see if that allows it to clean up the leftovers that were partially copied.
Old 08-29-2008, 04:05 AM   #3
LQ Newbie
Registered: Aug 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Problem is than I'm using rsync to copy about 100GB of data. This will take several days, as the connection speed is really slow.

This can only be done at nights, so I have CRON launching a bash script, which launches the rsync. This script has to end exactly at 8:00 in the morning, so CRON launches another script at that time to stop the first one.

Rsync copies whole folders, so I can't ask it to end between two individual files, so I assume my only chance is to kill it. I tried with kill -15 and it also leaves the temp file behind. I tried with some other signals, but all yield the same result.
Old 08-29-2008, 04:25 AM   #4
Senior Member
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
How exactly does cron stop the running rsync? You don't kill -9, do you?
In my experience, Ctrl+C or kill -15 get the same clean result because the program IS able to react to both BEFORE leaving. Not a single chance with kill -9 though.

Old 08-29-2008, 06:59 AM   #5
LQ Newbie
Registered: Aug 2008
Posts: 6

Original Poster
Rep: Reputation: 0
At the moment I use this command:
pkill -P $(pgrep -f "")

This line kills and the rsync that was launched by the program.

I already tried kill -15. This is the test I did:

In one terminal I launch:
rsync -av test.bin ./files/
test.bin is a 300MB file, so it gives me some time to kill rsync.

In another terminal I do "ps aux" to find the pid of rsync, and then "kill -15 9280".

rsync then terminates with the following message:

rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(255) [sender=2.6.8]

And the file .test.bin.76wBm6 is left behind in the ./files/ folder.
Old 08-29-2008, 07:03 AM   #6
Senior Member
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 54
Instead of killing it in the middle, and having it possibly never finish, leaving you with perpetually unbacked-up files why don't you create a PID file in /tmp? The script should check for the existence of this file and if it exists then don't start a new instance.

This is what I do for my cron jobs.

Edit: I realize you don't want it to continue running after 8:00 A.M. I still think this isn't what you really want if you can't copy everything. Can't you let it finish? BTW, after it finishes once it will be alot faster the next time. rsync is smart about not copying stuff that exists on the receiving end.

Last edited by Randux; 08-29-2008 at 07:06 AM.
Old 08-29-2008, 07:15 AM   #7
LQ Newbie
Registered: Aug 2008
Posts: 6

Original Poster
Rep: Reputation: 0
At 8 AM, people start working, and they need the internet connection to be free, as it is already very slow, that's why I have to stop it even if it is in the middle of transferring a file.

I only need this working for the next 2-3 weeks, since when the synchronization finishes, it will only take a few hours to copy the new files added that day.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh is not closing cleanly dasy2k1 Linux - Networking 2 12-03-2007 11:23 AM
How do i cleanly stop a service? n0vembr Linux - General 18 07-29-2005 05:11 AM
How to remove perl cleanly jpan Linux - Software 1 11-06-2004 09:36 AM
hda2 not cleanly unmounting Ratclaws Linux - General 8 06-10-2002 09:09 AM
...not cleanly unmounted error? RonRussell Linux - General 0 03-15-2002 04:35 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:53 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration