App-rsync-new2old
view release on metacpan or search on metacpan
script/rsync-new2old view on Meta::CPAN
=head1 SYNOPSIS
Use like you would use B<rsync>:
% rsync-new2old -avz [other options...] <source> <target>
=head1 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, B<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 C<source> is C<2016-12-16T01:00:00> (the mtime of C<file2>),
while the newest mtime of C<target> is C<2016-12-06T00:00:00> (the mtime of
C<file2> or C<dir1>). B<rsync-new2old> will allow synchronizing from C<source>
to C<target>.
Caveats: Note that C<source> and C<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.
=head1 OPTIONS
=head2 --help, -h, -?
script/rsync-new2old view on Meta::CPAN
B<rsync>, L<rsynccolor>.
Other one-way mirroring tools:
=over
=item * ZFS send and receive, L<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.
=back
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:
=over
=item * B<unison>, L<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.
=item * Version control tools, like B<git>, B<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.
=back
=head1 AUTHOR
perlancar <perlancar@cpan.org>
=head1 COPYRIGHT AND LICENSE
( run in 0.547 second using v1.01-cache-2.11-cpan-0d8aa00de5b )