NAME
rsync-new2old - Rsync wrapper to make sure we sync new data to old, not otherwise
VERSION
This document describes version 0.001 of rsync-new2old (from Perl distribution App-rsync-new2old), released on 2016-12-15.
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 another (A). Then I forgot 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
.
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.
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
Other one-way mirroring tools:
rsync
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 and 2-way mirroring capability.
gitbunch from Git::Bunch
When synchronizing a file or non-repo directory, will do the same newest-mtime check first like rsync-new2old.
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) 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.