NAME

rsync-new2old - Rsync wrapper to make sure we sync new data to old, not otherwise

VERSION

This document describes version 0.008 of rsync-new2old (from Perl distribution App-rsync-new2old), released on 2019-03-28.

SYNOPSIS

Use like you would use rsync:

% rsync-new2old -avz [other options...] <source> <target>

DESCRIPTION

Rsync is a fast and versatile directory mirroring tool. I often use it to synchronize my large media/software directory from one computer to another. However, sometimes I add/delete stuffs from this directory on one computer (say B) instead of on another (A). Then I forget and synchronize the media directory from A to B instead of B to A. The changes in B are then lost.

This tool, rsync-new2old, is a simple rsync wrapper that will first check that the newest modification filestamp (mtime) of file/subdirectory in source directory is not older than the newest mtime of file/subdirectory in target directory. If that check passes, it runs rsync. If not, it aborts.

Illustration:

source/
  dir1/          -> mtime: 2016-12-15T00:00:00
    file1        -> mtime: 2016-12-15T00:00:00
    file2        -> mtime: 2016-12-16T01:00:00

target/          -> mtime: 2016-12-05T00:00:00
  dir1/          -> mtime: 2016-12-06T00:00:00
    file2        -> mtime: 2016-12-06T00:00:00

The newest mtime in source is 2016-12-16T01:00:00 (the mtime of file2), while the newest mtime of target is 2016-12-06T00:00:00 (the mtime of file2 or dir1). rsync-new2old will allow synchronizing from source to target.

Caveats: Note that source and target must be local filesystem paths, so this wrapper cannot be used if one of source/target is a remote path. Also, this script currently doesn't regard rsync --exclude options. Please consider the alternatives mentioned in the See Also section.

OPTIONS

--help, -h, -?

--version

--create-target-if-not-exists

ENVIRONMENT

RSYNC_NEW2OLD_RSYNC_CMD

String. Rsync command to use. Defaults to rsynccolor (if available on PATH) or rsync. Can be used to chain several rsync wrappers together.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/App-rsync-new2old.

SOURCE

Source repository is at https://github.com/perlancar/perl-App-rsync-new2old.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-rsync-new2old

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

rsync, rsynccolor.

Other one-way mirroring tools:

  • ZFS send and receive, https://docs.oracle.com/cd/E18752_01/html/819-5461/gbchx.html

    Filesystems like ZFS also record changes to filesystems and can propagate them to another filesystem efficiently. If you are synchronizing between two ZFS filesystems (even across network), this approach offers great performance (e.g. detect renames and can propagate this change quickly instead of rsync which must delete files with old names + re-copy the same files with new names) and 2-way mirroring capability.

A safer solution when you want to synchronize two directories while maintaining changes from both directories is to use 2-way mirroring solutions. Below are some:

  • unison, https://www.cis.upenn.edu/~bcpierce/unison

    A two-way mirroring tool which also uses the rsync algorithm to transfer data. It works by first recording the state of a directory (all the mtimes, permissions, etc of its files). Then, when you want to synchronize this directory, it will calculate the changes between the current state and the previous, then negotiate it with the changes in the target directory. It can propagate files added/deleted from either directory, and can detect files that are changed in both directory (a conflict). It does not merge conflicts.

    I found rsync faster when transferring large directories, so I usually just use rsync.

  • Version control tools, like git, mercurial, etc

    These tools can propagate changes from either direction including merging conflicts (changes to the same file). Many however are not designed to store large binaries so using these tools to synchronize large binaries can result in inefficient disk storage or slow performance.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019, 2018, 2017, 2016 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.