简体   繁体   English

拉动镜像git存储库?

[英]Mirror a git repository by pulling?

I am wondering if there is an easy way, ie like a simple cron job, to regularly pull from 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服务器死亡,我们有一个备份位置,我们可以手动故障转移到。

First create a mirror with 首先创建一个镜像

git clone --mirror git@somewhere.com: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. 也许你想要不那么频繁地做这件事。

As Andrew noted, every clone of a git repo is a full-fledged backup of the repo. 正如Andrew所指出的,git repo的每个克隆都是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. 不需要cron作业或rsync,它几乎是一个真实的副本。

do you have direct access to the server? 你有直接访问服务器的权限吗? then you could just rsync the .git directory 然后你可以只是rsync .git目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM