【发布时间】:2015-07-16 07:14:28
【问题描述】:
我有一个通过 ssh 访问的 git。我想通过镜像将服务器备份到另一个位置。我有另一台服务器,我可以在其中设置另一个 git 存储库。
我的想法是:以某种方式将服务器 1 的提交自动转发到服务器 2,这可能吗?
【问题讨论】:
-
“自动转发”是什么意思?
-
我的意思是:服务器A自动向服务器B发送更改
我有一个通过 ssh 访问的 git。我想通过镜像将服务器备份到另一个位置。我有另一台服务器,我可以在其中设置另一个 git 存储库。
我的想法是:以某种方式将服务器 1 的提交自动转发到服务器 2,这可能吗?
【问题讨论】:
要在对存储库执行推送后自动执行操作,可以使用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.
【讨论】:
你可以使用
git clone
如果您在备份服务器上安装了客户端客户端。然后可以将其设置为定期运行以进行自动更新。
【讨论】: