维护和同步镜像远程Git存储库 [英] Maintaining and synchronizing a mirror remote Git repository

查看:130
本文介绍了维护和同步镜像远程Git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近使用远程git服务器(我自己的电脑),服务器出现故障,无法远程访问。

我想知道是否有合适的方法来维护两个远程存储库,以便我的另一台计算机上的第二个存储库可以自动使用当第一个失败?



我的第二个问题是如何自动(例如通过脚本)定期同步主要和备份远程存储库,以及如何更改一个是默认的/主要的depo?



我的日常用例非常简单,如下所示:

  git克隆用户@主机:A.git 
cd A
(修改代码..)
git add。
git commit -m...
git push
git pull ....

因此,这里没有分支和冲突不是我关心的。主数据库和备份数据库应该是不同时间点的相同工作的快照。其中一些可能由于无障碍问题而落后。

我不是问如何设置(裸)远程depo的基本知识,并使用ssh进行常规推拉。我问的是如果有一种方法可以在主服务器和备用服务器之间自动切换,当其中一个服务器出现故障时。



谢谢。



< - >编辑---



澄清,我的问题归结为:

是否有设置两个远程存储库的方法,如镜像RAID(磁盘阵列),其中


  1. a pull 请求从最新的回购中拉出,并且 push 请求将更改推送到所有实时镜像。

  2. 如果其中一个回购股票下跌并再次回来,它将收回其他回购股份累计的变化。

  3. >

注意:有一个旧帖子这里,它提出了一个相关的问题。但是那里的答案并没有解决同步问题,并且当多个回购变得不同步时会发生什么。 可以在任何地方维护第二个裸回购(如USB磁盘),并立即自动推入两个遥控器。

请参阅从多个远程位置拉/推



或者你可以设置一个脚本来做备份,这在Git a 软件包

我最近编写了一个脚本,它可以:





您可以运行在任何时候脚本:如果没有创建新的提交,它将不会执行任何操作。



捆绑包的理念是将回购保存为一个文件(比在 .git 树中保存大量文件更安全,并且更容易复制)。


I am recently using a remote git server (my own computer), and the server malfunctioned and can't be remotely accessed.

I was wondering if there is a proper way to maintain TWO remote depositories, so that the second depository on my other computer can be automatically used when the first one fails?

My second question is how to automatically (e.g. via a script) to synchronize the primary and backup remote depositories periodically, and how can I change which one is the default/primary depo?

My daily use case is pretty simple, as follows:

git clone user@host:A.git
cd A
(modify code ..)
git add .
git commit -m "..."
git push
git pull ....

So, there is no branching and conflicts is not my concern here. The primary and the backup(s) repos should just be snapshots of the same work at different points of time. Some of them may be lagging behind because of accessibility issues.

P.S. I am not asking the basics of how to set up a (bare) remote depo, and do regular push-pulls using ssh. What I am asking is if there is a way to automatically switch between a primary and a backup repo when one of them fails.

Thanks.

--- EDIT ---

To clarify, my question boils down to this:

Is there a way to setup two remote repositories like a mirroring RAID (disk array), where

  1. a pull request pulls from the the most up-to-date repo, and a push request pushes changes to all live mirrors.

  2. If one of the repos went down, and come back again, it will pick up the changes accumulated in other repos.

Note: there is an old post here, which asks a related question. But the answers there did not address the synchronization problem, and what happens when multiple repos become out-of-sync.

解决方案

You could maintain a second bare repo anywhere you want (like an usb disk), and push automatically on both remotes at once.
See "pull/push from multiple remote locations".

That or you can setup a script which does a backup, which is called in Git a bundle.
I have written recently a script which does:

You can run that script at any time: if no new commits have been created, it won't do anything.

The idea behind bundles is to save a repo as one file (much safer than saving a large number of files in a .git tree, and easier to copy around).

这篇关于维护和同步镜像远程Git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆