LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   What happens if you run the same rsync command twice (http://www.linuxquestions.org/questions/linux-general-1/what-happens-if-you-run-the-same-rsync-command-twice-4175456303/)

rjo98 03-31-2013 06:53 PM

What happens if you run the same rsync command twice
 
I have a somewhat silly question. Say I have an rsync job setup in cron to run every 4 hours. For example, say it's 4am and the cron job kicks off. What happens if at 4:15am that cron'd rsync is still running, and someone logs on to the server and runs the exact same rsync command manually?

Will this cause issues or bad data? Will the user manually running it have something pop up on the screen saying that rsync is already doing something in these folders or anything?

If it matters, I usually use these options when I rsync (took it from one that was already setup by someone else on another server of mine)
-razpv -e ssh

jpollard 04-01-2013 07:51 AM

I don't think anything will really happen - the files that were already synced will not be resynced as they already match for being updated.

You MIGHT get duplicate copying... but the one that finishes last will be the final copy, and the only way they would differ would be if the file changed while the first copy was being made, and the second copy got the updated blocks.

The only time corruption should occur is if the second rsync gets aborted in the middle of copying - it might truncate the file (I'm not sure though).

rjo98 04-01-2013 07:54 AM

I'm also thinking it might not be a huge deal, but really I'm not sure.

rknichols 04-01-2013 11:38 AM

If it's between two locally mounted filesystems, I suspect you could probably get away with it. But, if either filesystem is remote (so that rsync tries to transmit diffs rather than whole files), I have bad feelings about what might happen if one instance calculates a diff and transmits it, but the other instance has updated the file in the meantime.

lleb 04-01-2013 12:01 PM

if the first rsync is still running the 2nd one will not be allowed to run, you can only have one instance of rsync running at a time. its not a big deal.

rknichols 04-01-2013 12:57 PM

Quote:

Originally Posted by lleb (Post 4922880)
if the first rsync is still running the 2nd one will not be allowed to run, you can only have one instance of rsync running at a time. its not a big deal.

Perhaps that's true if you're connecting to a remote rsync server that was spawned as a service (I have no experience with that.), but it's certainly not true when running rsync with both source and destination local or when the remote process is spawned by a remote shell. I just tried it both ways, always with the same sources and same destinations, with no complaints from rsync.

rjo98 04-01-2013 04:31 PM

That's a good point about a remote vs local rsync


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