前言
如果手上经常有大量数据需要跨服务器转移,那么rsync真的是个好东西!功能非常的丰富,这里记录一下自己实际使用的案例,不定期增加内容和更新。
inplace参数:实现块文件/镜像文件增量备份与复制
--inplace
This option changes how rsync transfers a file when the file's data needs to be updated: instead of the default method of creating a new copy of the file and moving it into place when it is complete, rsync instead writes the updated data directly to the destination file.
This has several effects: (1) in-use binaries cannot be updated (either the OS will prevent this from happening, or binaries that attempt to swap-in their data will misbehave or crash), (2) the file’s data will be in an inconsistent state during the transfer, (3) a file’s data may be left in an inconsistent state after the transfer if the transfer is interrupted or if an update fails, (4) a file that does not have write permissions can not be updated, and (5) the efficiency of rsync’s delta-transfer algorithm may be reduced if some data in the destination file is overwritten before it can be copied to a position later in the file (one exception to this is if you combine this option with –backup, since rsync is smart enough to use the backup file as the basis file for the transfer).
WARNING: you should not use this option to update files that are being accessed by others, so be careful when choosing to use this for a copy. This option is useful for transfer of large files with block-based changes or appended data, and also on systems that are disk bound, not network bound. The option implies –partial (since an interrupted transfer does not delete the file), but conflicts with –partial-dir and –delay-updates. Prior to rsync 2.6.4 –inplace was also incompatible with –compare-dest and –link-dest.
简而言之就是:
1. rsync默认情况下是将更新的文件复制到目标路径后替换旧文件
default method of creating a new copy of the file and moving it into place when it is complete
2. 加上这个参数之后,rsync会将更新的部分直接写入目标路径对应的位置
writes the updated data directly to the destination file
3. 适合的情况是当源文件一直在变动或者源文件是一个块文件的情况
实例
在我们实际使用中,如果需要将一个正在运行的虚拟机镜像进行复制同步,那么就必须使用这个参数。否则当虚拟机在写入的时候复制就会出现文件损坏了。
命令(其中r操作目录 v显示更多信息 progress显示进度):
[root@KVM-FSN1-M103 /]# rsync -r -v --progress --inplace --no-whole-file /storage/data/ /storage-new/data/