rsync 和文件权限 - linux

rsync 和文件权限 - linux

我正在尝试使用 rsync 将一组文件从一个系统复制到另一个系统。我以普通用户(不是 root)身份运行该命令。在远程系统上,这些文件归 apache 所有,而复制时,它们显然归本地帐户(fred)所有。

我的问题是,每次运行 rsync 命令时,所有文件都会重新同步,即使它们没有更改。我认为问题是 rsync 看到文件所有者不同,并且我的本地用户无法将所有权更改为 apache,但我没有包括或选项,-a所以-o我认为这不会被检查。如果我以 root 身份运行该命令,文件将归 apache 所有,如果我再次运行该命令,则不会再次出现。但是由于其他原因,我无法以 root 身份运行此命令。以下是命令:

/usr/bin/rsync --recursive --rsh=/usr/bin/ssh --rsync-path=/usr/bin/rsync --verbose [email protected]:/src/dir/ /local/dir

答案1

以下是您问题的答案:

-c, --checksum
      This changes the way rsync checks if the files have been changed and are in need of a  transfer.   Without  this  option,
      rsync  uses  a "quick check" that (by default) checks if each file's size and time of last modification match between the
      sender and receiver.  This option changes this to compare a 128-bit checksum for each file  that  has  a  matching  size.
      Generating  the  checksums  means  that both sides will expend a lot of disk I/O reading all the data in the files in the
      transfer (and this is prior to any reading that will be done to transfer changed files), so this  can  slow  things  down
      significantly.

      The  sending  side  generates  its checksums while it is doing the file-system scan that builds the list of the available
      files.  The receiver generates its checksums when it is scanning for changed files, and will checksum any file  that  has
      the  same  size  as the corresponding sender's file:  files with either a changed size or a changed checksum are selected
      for transfer.

      Note that rsync always verifies that each transferred file was correctly reconstructed on the receiving side by  checking
      a  whole-file  checksum  that is generated as the file is transferred, but that automatic after-the-transfer verification
      has nothing to do with this option's before-the-transfer "Does this file need to be updated?" check.

      For protocol 30 and beyond (first supported in 3.0.0), the checksum used is MD5.  For older protocols, the checksum  used
      is MD4.

因此运行:

/usr/bin/rsync -c --recursive --rsh=/usr/bin/ssh --rsync-path=/usr/bin/rsync --verbose [email protected]:/src/dir/ /local/dir

请注意,使用此选项可能会产生时间+磁盘流失的权衡。就我个人而言,我可能也会同步文件的 mtime:

/usr/bin/rsync -t --recursive --rsh=/usr/bin/ssh --rsync-path=/usr/bin/rsync --verbose [email protected]:/src/dir/ /local/dir

相关内容