通过拉取镜像 git 存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2756747/
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-10 08:20:30  来源:igfitidea点击:

Mirror a git repository by pulling?

gitmirror

提问by corydoras

I am wondering if there is an easy way, ie like a simple cron job, to regularly pullfrom a remote git repository to a local read only mirror for backup purposes?

我想知道如果有一个简单的方法,即是一个简单的cron作业,定期从一个远程git仓库到本地只读用于备份镜像?

Ideally it would pull all branches and tags, but the master/trunk/head would be sufficient.

理想情况下,它会拉出所有分支和标签,但主/主干/头就足够了。

I just need a way to make sure that if the master git server dies, we have a backup location that we could manually fail over to.

我只需要一种方法来确保如果主 git 服务器死机,我们有一个可以手动故障转移到的备份位置。

回答by gregor

First create a mirror with

首先创建一个镜像

git clone --mirror [email protected]:repo.git

then setup a cron job like this:

然后像这样设置一个 cron 作业:

*/1 * * * * gitbackup cd /backup/repo.git && git fetch -q --tags

This will backup the changesets every minute. Maybe you want to do this less frequently.

这将每分钟备份一次变更集。也许你想不那么频繁地这样做。

回答by J. Cordasco

As Andrew noted, every clone of a git repo is a full-fledged backup of the repo. That said, if you want something backed up automatically to a particular machine, you can create a bare repo on the backup server, push into it with all the branches you want backed up in order to initially populate it. Then just setup a post update hook on the "main" repo so that as soon as there are commits pushed in, it goes ahead and pushes them to the backup repo. No need for a cron job or rsync, and its an almost live copy.

正如 Andrew 所指出的,git 存储库的每个克隆都是该存储库的完整备份。也就是说,如果您希望将某些内容自动备份到特定机器上,您可以在备份服务器上创建一个裸仓库,将您想要备份的所有分支推入其中,以便最初填充它。然后只需在“主”存储库上设置一个更新后挂钩,以便一旦有提交推送,它就会继续将它们推送到备份存储库。不需要 cron 作业或 rsync,它几乎是实时副本。

回答by knittl

do you have direct access to the server? then you could just rsyncthe .gitdirectory

你可以直接访问服务器吗?然后你可以只rsync.git目录