An Rsync Question

Home » CentOS » An Rsync Question
CentOS 4 Comments

Is there any way to have rsync compare against a file with a *different*

What I’d like to do is compare a vm – whatsit.img against a backup –
whatsit.current, that’s a symlink to whatsit.timestamp, and if different,
*then* make the copy (which my script will then move to whatsit.newtimestamp, and change the symlink to point to the new one, then remove the old (or maybe save an older copy or two).

\ whatsit.20130101 (backup of whatsit.img)
whatsit.current -> whatsit.20130101

After script w/ rsync backupdir
\ whatsit.20130201 (backup of whatsit.img)
whatsit.current -> whatsit.20130201


4 thoughts on - An Rsync Question

  • I think that rsync might overwrite or get confused by your symlinks, regardless of the actual filenames.

    You might be better off using something like md5sum or sha1sum or the like to compare checksums between your files and then make a new copy or not based on that result.

  • I don’t think you can do it with symlinks (maybe with -L??), but a hard link with the same name should work. Normally rsync builds a new copy and renames it to the old name only after completion so any other link names should keep the old data (unlike programs that would overwrite the existing data). Or just let rsync do all the work itself with the –backup-dir option. With that, if the target differs it will update it and move a copy of the outdated version into the specified directory.

  • I’m not quite sure what you are trying to do. A couple of things that I do include:

    1) By referencing ‘whatsit.current/.’ you can be sure to follow a symbolic link on the destination of the rsync. I do this all the time when wanting a different destination directory name.

    2) You can use the –link-dest rsync option to create a new tree based upon an older tree. I don’t have an example handy but it looks something like:

    rsync -aH –link-dest=whatsit-current/. whatsit: whatsit-new

    3) Preserve historic backups as hard links (using ‘cp’). This leaves
    ‘backup/whatsit’ as the current version (slightly inconsistent during the backup operation).

    * rsync -aH –delete whatsit: backup/whatsit
    * monday-saturday: cp -rpl backup historic/daily-YYYYMMDD
    * sunday: cp -rpl backup historic/weekly-YYYYMMDD
    * clean up older daily-YYYYMMDD files after 1 month

    Some combination of these may help with what you are attempting.

    4) I assume you are comparing the contents of the VM disk (as seen by the virtual OS) not the data blocks in the container file itself. rsync is probably not very useful for just the single container disk image file (it might have slight use for vmware disk images composed of many smaller storage segments).


  • Stuart Barkley wrote:


    Duhhhhh… Lost: small, squishy wrinkled grey thing. If found, return here, sentimental value only.

    I think rsync -HPavx whatsit.img backup_dir/
    ln backup_dir/whatsit.img backup_dir/whatsit.
    solves my problem.