概括: 迁移bitbucket后,发现部分分支commit缺失。

迁移过程:

  1. 对数据目录进行初次同步。使用命令/bin/rsync -auvP --delete -e "ssh -p 10022" /source/dir/ root@dest.host:/dest/dir/ >> /tmp/rsync_rst.log 2>&1
  2. 正式迁移开始前停止老Bitbucket的服务
  3. 对数据目录进行增量同步(由于操作失误忘记加--delete参数)

分析:

通过google发现官方文档 部分解释如下

While running this sequence of commands, the –delete rsync option is not used so only changes to existing files and new files are synchronized. However, files that have been copied during the earlier rsync are not deleted and this causes unexpected conflicts in the Git repositories.

1
2
3
4
5
6
7
8
9
At certain intervals, Bitbucket runs a git pack-refs --all (see git-pack-refs for git-pack-refs documentation) causing the files containing the refs to the tip of the branch to be packed to the $REPOSITORY_HOME/packed-refs file.

The file containing the refs, stored as $REPOSITORY_HOME/refs/heads/feature/<branch_name>, is emptied as part of this process.



If the first rsync has been performed before the pack-refs ran and again after that without the --delete option, both the $REPOSITORY_HOME/refs/heads/<branch_name> and the $REPOSITORY_HOME/packed-refs file will be present in the target filesystem.

When that happens, git recognizes the hash in $REPOSITORY_HOME/refs/heads/<branch_name> as the tip of the branch but this is now outdated and leads to what is described as "missing commits".

解决: 删除原同步内容,重新同步。

Tips: 无谓的尝试

  • 期间尝试手动使用touch命令更改最近修改的时间戳以使得rsync重新进行同步,结果确实对这部分内容进行了重传,不过问题依旧
  • 又尝试使用rsync的--checksum指令进行md5校验重传(rsync默认是按照时间戳及文件大小),不过考虑到数据量较大,就没有尝试。