The inner workings of rsync

"Please leave a message at the beep, we will get back to you when your support contract expires."

Moderators: phlip, Prelates, Moderators General

The inner workings of rsync

Postby Jplus » Sun Nov 07, 2010 8:30 pm UTC

Hey folks,

I want to roll my own little backup script that works in a similar way as Apple's "Time Machine". For the most frequent backups, i.e. every hour or so, I want to use rsync. However, my entire approach depends on the way rsync treats files that have been modified. I couldn't find any answer to my question in the man pages, nor on the rsync website, nor on google.

This is my question: if rsync updates a file that has been modified, does it change the outdated file in-place, or does it unlink the old file and add a new directory entry for the updated file?

Suprise! You don't have to answer (if you know the answer at all), because I found out for myself. I ran a little test, where I synced one directory (the source) to the other (the target), hard-linked the file inside the target directory to a third directory, modified the original file in the source directory, re-synced, and finally compared the updated file in the target directory with the linked file in the third directory. The outcome: they were different. So rsync unlinks the old file rather than overwriting it in-place.

This happens to be what I hoped for, since once a day I'll make a hard-linked "meta-snapshot" of the current snapshot, and I don't want those "meta-shapshots" to be overwritten by new rsync updates.

Any comments?
Feel free to call me Julian. J+ is just an abbreviation.
Image coding and xkcd combined
User avatar
Jplus
 
Posts: 1560
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: classified

Re: The inner workings of rsync

Postby Carnildo » Sun Nov 07, 2010 11:51 pm UTC

Jplus wrote:This is my question: if rsync updates a file that has been modified, does it change the outdated file in-place, or does it unlink the old file and add a new directory entry for the updated file?

At least in the rsync I've got (rsync 3.0.7), you can control this with the use of the "--inplace" option. By default, rsync will write the new file under a temporary name, unlink the old file, and rename the temporary. If you specify the "--inplace" option, rsync will instead overwrite the existing file, with all the risks involved.

Incidentally, this is all there in the man page.
Carnildo
 
Posts: 2022
Joined: Fri Jul 18, 2008 8:43 am UTC

Re: The inner workings of rsync

Postby Jplus » Sun Nov 07, 2010 11:59 pm UTC

Yep, now I see it too. Having overlooked it twice, I feel very dumb now... :oops:
Feel free to call me Julian. J+ is just an abbreviation.
Image coding and xkcd combined
User avatar
Jplus
 
Posts: 1560
Joined: Wed Apr 21, 2010 12:29 pm UTC
Location: classified


Return to The Help Desk

Who is online

Users browsing this forum: No registered users and 12 guests