Maintaining and synchronizing a mirror remote Git repository

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-28 02:16:12

问题


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.


回答1:


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:

  • a full backup if the last one is over a week
  • an incremental backup (if new commits have been done)

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).



来源:https://stackoverflow.com/questions/23711058/maintaining-and-synchronizing-a-mirror-remote-git-repository

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!