我正在研究目录复制的rsync
脚本。 我只同步它只是新的和修改的文件或目录,但我不喜欢这样的事实,它复制重命名文件或目录作为一个新的文件或目录,保持文件不同步。 我还设置了1MB的带宽限制,因为这将在业务工作时间内运行。 这是我的脚本:
rsync -zvru --bwlimit=1024 /mymounts/test1/ /mymounts/test2
如果有人重命名某些内容,仍然只能复制新文件或修改过的文件,如何使文件和目录保持同步? 这里是有问题的文件
ls "/mymounts/test1/some stuff" new directory newfile1.txt newfile3.txt renamedFile.txt ls "/mymounts/test2/some stuff" new directory newfile1.txt newfile2.txt newfile3.txt renamedFile.txt
或者有没有办法甚至将重命名的文件移动到另一个目录说: /mymounts/VerControl
?
如果源和目标目录上的文件系统支持硬链接,则可以使用rsync
处理移动和重命名的文件。 这个想法是让rsync在实际传输之前重build硬链接。 你可以在这里find一个精彩的解释 。
我们结束了一个简单的解决scheme,在source / target目录中创build一个隐藏的硬链接树,基本脚本可能是这样的:
# Name of hidden directory Shadow=".rsync_shadow" # do real sync rsync -ahHv --stats --no-inc-recursive --delete --delete-after "$Source"/ "$Target" # update/create hidden dir of hard links in source rsync -a --delete --link-dest="$Source" --exclude="/$Shadow" "$Source"/ "$Source/$Shadow" # update/create hidden dir of hard links in target rsync -a --delete --link-dest="$Target" --exclude="/$Shadow" "$Target"/ "$Target/$Shadow"
我有一个GitHub上的示例脚本 。 但是我build议你在使用这种方法进行生产之前做大量的testing。
你可能想看看-y | --fuzzy
-y | --fuzzy
rsync选项。 除此之外,rsync没有办法跟踪重命名,所以你最终会传输重命名的文件。
从rsync的手册页:
-y, --fuzzy This option tells rsync that it should look for a basis file for any destination file that is missing. The current algorithm looks in the same directory as the destination file for either a file that has an identical size and modified-time, or a simi- larly-named file. If found, rsync uses the fuzzy basis file to try to speed up the transfer.
据我所知, 看artyom的答案。 rsync
无法识别文件的重命名新文件将不得不再次传输。
要删除已删除的文件,请确保使用--delete
选项。
此外,对于镜像,我会build议你使用-a
( 归档 ),这些别名一些不错的select。
有关详细信息,请参阅man 1 rsync
。
Rsync有三种模式,
然而这三种模式有两个子类别,
Rsync不会跟踪哪些文件被重命名,它没有状态。 请考虑复制所有文件,并排除不需要的文件。 你不能有一个移动白名单,你可以有一个黑名单。
rsync [..stuff..] --exclude 'lib/'