简体   繁体   English

备份和还原gitosis和其他git仓库

[英]Backing up and restoring gitosis and other git repos

I am trying to backup gitosis and a repository to a backup tarball and then restore and test on a blank system to ensure that in case of complete server failure that I can get a new system running quickly. 我试图将gitosis和存储库备份到备份tarball,然后在空白系统上进行还原和测试,以确保在服务器完全故障的情况下,我可以使新系统快速运行。

I have the two directories using 我有两个目录使用

git clone --mirror gitosis@localhost:gitosis-admin.git gitosis-backup.repo
git clone --mirror gitosis@localhost:test1.git test1-backup.repo

And then taring up 然后去皮

On my cleanly installed machine I have extracted the tarballs and done 在干净安装的机器上,我提取了压缩包并完成了

git clone gitosis-backup.repo gitosis-admin
git clone test1-backup.repo test1

Going into the the two directories and doing git log shows the history. 进入两个目录并执行git log显示历史记录。

But this isn't committed to the new server. 但这并没有提交给新服务器。 But doing git push origin master doesn't work and it claims to be up-to-date. 但是,执行git push origin master无效,并且声称它是最新的。

But any attempt to do a clone from my new server fails as, quite rightly, the repo isn't actually part of the server. 但是,从我的新服务器进行克隆的任何尝试都将失败,因为正确的是,存储库实际上并不是服务器的一部分。

So how do I finish the job? 那我该如何完成工作呢? I have been unable to find an answer about restoring gitosis on this site or any other. 我一直无法在此站点或任何其他站点上找到有关恢复gitosis的答案。

Output from testing with the help from VoC is as follows 在VoC的帮助下测试的输出如下

mkdir git_restore
cd git_restore
mkdir tarballs
cd tarballs
cp ~/backup/*.tgz
tar -zxf gitosis-admin.repo.tgz
tar -zxf test1-backup.repo.tgz

cd ..
mkdir local_repo
cd local_repo

ssh-keygen

sudo apt-get install gitosis

sudo -H -u gitosis gitosis-init < /home/ian/.ssh/id_rsa.pub

ls /srv/gitosis/git # check that this is not a broken sym link

git clone gitosis@localhost:gitosis-admin

cd gitosis-admin

git log # Has the initialise entry

cd ../..

mkdir restore

cd restore

git clone ../tarballs/gitosis-admin.repo gitosis-admin
git clone ../tarballs/test1-backup.repo test1

cd gitosis-admin

git log # Full log is present

git push gitosis@localhost:gitosis-admin master
To gitosis@localhost:gitosis-admin
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'gitosis@localhost:gitosis-admin'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

git status
# On branch master
nothing to commit (working directory clean)

git fetch

git merge origin master
Already up-to-date. Yeeah!

git push gitosis@localhost:gitosis-admin master
To gitosis@localhost:gitosis-admin
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'gitosis@localhost:gitosis-admin'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

As an aside doing git push gitosis@localhost:gitosis-admin origin/master seems to push, but then if I then do a clone of the gitosis-admin in a separate directory and then do git log then I just have the initialisation entry. 顺便说一句,执行git push gitosis @ localhost:gitosis-admin origin / master似乎要进行推送,但是如果我然后在单独的目录中进行gitosis-admin的克隆,然后执行git log,那么我只有初始化条目。

If you are using ssh addresses, as described in " Setting up git securely and easily using gitosis ", you need to make sure the gitosis admin account has the right ~gitosis/.ssh/authorized_keys that you has on your first server, plus the public and private keys initially used to clone the gitosis-admin.git repo. 如果您使用的是ssh地址(如“ 安全且轻松地使用gitosis设置git ”中所述),则需要确保gitosis管理员帐户具有正确的~gitosis/.ssh/authorized_keys在第一台服务器上具有),以及最初用于克隆gitosis-admin.git库的公共和私有密钥。

To summarize the comments below: 总结以下评论:

  • install gitosis on the server 在服务器上安装gitosis
  • make sure your ssh daemon is working on said server 确保您的ssh守护程序在所述服务器上正常工作
  • generate a new key (still on the server) which will allows you to clone the gitosis-admin repo 生成一个新密钥(仍在服务器上),将允许您克隆gitosis-admin
  • untar your backup repos on your local workstation 将备份存储库解压缩到本地工作站上
  • git push --force your local gitosis-admin back on the server, using the new account with the new key. git push --force使用带有新密钥的新帐户,将本地gitosis-admin返回服务器。

由VonC解决,方法是指出(a)我必须先初始化gitosis,然后才能执行任何操作,并且(b)需要使用--force命令才能进行推送。

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

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