Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

backup - Maintaining and synchronizing a mirror remote Git repository

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...