【问题标题】:Automatically mirror git repository自动镜像 git 存储库
【发布时间】:2015-07-16 07:14:28
【问题描述】:

我有一个通过 ssh 访问的 git。我想通过镜像将服务器备份到另一个位置。我有另一台服务器,我可以在其中设置另一个 git 存储库。

我的想法是:以某种方式将服务器 1 的提交自动转发到服务器 2,这可能吗?

【问题讨论】:

  • “自动转发”是什么意思?
  • 我的意思是:服务器A自动向服务器B发送更改

标签: git mirroring


【解决方案1】:

要在对存储库执行推送后自动执行操作,可以使用post-receive 挂钩。整个推送过程完成后会被调用。

您只需使用标准的git push--mirror [1] 选项即可推送到另一台服务器:

#!/bin/bash
git push --mirror git@example.com:mirror.git

[1]

   --mirror
       Instead of naming each ref to push, specifies that all refs under
       refs/ (which includes but is not limited to refs/heads/,
       refs/remotes/, and refs/tags/) be mirrored to the remote
       repository. Newly created local refs will be pushed to the remote
       end, locally updated refs will be force updated on the remote end,
       and deleted refs will be removed from the remote end. This is the
       default if the configuration option remote.<remote>.mirror is set.

【讨论】:

  • 有没有办法使用ssh密码?
  • @greywolf82 我建议为此使用 SSH 密钥。您可以在 GitHub 帮助中了解它们:help.github.com/articles/generating-ssh-keys 在服务器 A 上生成 SSH 密钥并将其添加到服务器 B 的正确帐户中。
【解决方案2】:

你可以使用

git clone

如果您在备份服务器上安装了客户端客户端。然后可以将其设置为定期运行以进行自动更新。

【讨论】:

    猜你喜欢
    • 2013-03-30
    • 2012-08-14
    • 2013-08-01
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多