为 Gerrit 及其所有 Git 存储库设置镜像的最佳方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8828914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:20:03  来源:igfitidea点击:

Best way to setup mirror for Gerrit and all of its Git repos

gitmirrorgerrit

提问by xbeta

I have a Gerrit server (named A), and I want to setup a mirror to a new server (named B). I want to pull from B instead of using the processing power from A because A serves as the main Gerrit server and I don't want to put more workload on it when I can mirror it using SSH from B.

我有一个 Gerrit 服务器(名为 A),我想设置一个到新服务器(名为 B)的镜像。我想从 B 拉取数据,而不是使用 A 的处理能力,因为 A 作为主要 Gerrit 服务器,当我可以使用来自 B 的 SSH 进行镜像时,我不想给它增加更多的工作量。

I'm using H2 database and I want to mirror the whole Gerrit + all of its Git repos, not just simply Git repos because I want to keep the permissions/history from the Gerrit database too.

我正在使用 H2 数据库,我想镜像整个 Gerrit + 它的所有 Git 存储库,而不仅仅是 Git 存储库,因为我也想保留 Gerrit 数据库中的权限/历史记录。

I had managed to narrow down 2 possible ways to do it:

我设法缩小了两种可能的方法来做到这一点:

  1. Using 'gerrit replicate' http://gerrit.googlecode.com/svn/documentation/2.1.6/cmd-replicate.htmlNot sure what it meant by "[--url < PATTERN >]". Where should I put run this command? Is it on server A or B?

  2. Use 'rsync' which is OK, but then I cannot sync review_site/etc/gerrit.config because it contains the IP of server A and don't want to have that on server B.

  1. 使用'gerrit replication' http://gerrit.googlecode.com/svn/documentation/2.1.6/cmd-replicate.html不确定“[--url < PATTERN >]”是什么意思。我应该把运行这个命令放在哪里?是在服务器 A 还是 B 上?

  2. 使用 'rsync' 没问题,但是我无法同步 review_site/etc/gerrit.config,因为它包含服务器 A 的 IP,并且不想在服务器 B 上使用它。

回答by Brad

A few comments on the different issues here:

对这里不同问题的一些评论:

  1. There is no good way to perform a hot backup of the database and the repositories, especially if you are using H2. The only option to shut down Gerrit and use a file transfer tool like rsync. If you use a more robust database, like postgres, there are other backup option. However, you still have potential race conditions - if you back up the repositories before a change gets submitted and back up the database after, you might have problems. This is why long-term we are working to get rid of the database and store everything in the repositories.

  2. Push vs Pull is not much different as far as CPU load on the server (as far as I know). Just use the replication features built in to Gerrit, they are designed for this sort of thing.

  3. If Server B is just meant as a backup in case Server A goes down, I'd just write a script which stops Gerrit on Server A in the middle of the night, rsyncs to Server B, and starts Gerrit back up. That is about the best you can do right now, especially with H2.

  4. If Server B is meant to be a slave of your master (so some users can hit it rather than everybody hitting Server A), use Gerrit replication and slave mode - http://gerrit.googlecode.com/svn/documentation/2.1.6/config-gerrit.html#container. Note that this doesn't backup your database or changes in review.

  5. Gerrit 2.1.6 is reallyold. Use at least 2.1.8, 2.2.2 will be released soon and is your best bet

  6. The 'gerrit replicate' command is just meant to kick off replication in case the server was down the last time Gerrit tried to replicate. The instructions for setting up replication with 2.1.6 are at http://gerrit.googlecode.com/svn/documentation/2.1.6/config-replication.html

  1. 没有好的方法可以对数据库和存储库执行热备份,尤其是在您使用 H2 的情况下。关闭 Gerrit 并使用文件传输工具(如 rsync)的唯一选择。如果您使用更强大的数据库,如 postgres,还有其他备份选项。但是,您仍然存在潜在的竞争条件 - 如果您在提交更改之前备份存储库并在提交更改之后备份数据库,您可能会遇到问题。这就是为什么我们长期致力于摆脱数据库并将所有内容存储在存储库中的原因。

  2. 就服务器上的 CPU 负载(据我所知)而言,推与拉没有太大区别。只需使用 Gerrit 内置的复制功能,它们就是为这种事情而设计的。

  3. 如果服务器 B 只是作为服务器 A 出现故障的备份,我只需编写一个脚本,在半夜停止服务器 A 上的 Gerrit,同步到服务器 B,然后启动 Gerrit 备份。这大概是您现在可以做的最好的事情,尤其是使用 H2。

  4. 如果服务器 B 是您的主服务器的从属(因此某些用户可以访问它而不是每个人都访问服务器 A),请使用 Gerrit 复制和从属模式 - http://gerrit.googlecode.com/svn/documentation/2.1。 6/config-gerrit.html#container。请注意,这不会备份您的数据库或审核中的更改。

  5. Gerrit 2.1.6真的很老了。至少使用 2.1.8,2.2.2 即将发布,是您最好的选择

  6. 'gerrit replication' 命令仅用于在 Gerrit 上次尝试复制时服务器关闭的情况下启动复制。使用 2.1.6 设置复制的说明位于http://gerrit.googlecode.com/svn/documentation/2.1.6/config-replication.html