备份和恢复gitosis和其他git回购

时间:2012-09-25 19:19:06

标签: git backup restore gitosis

我正在尝试将gitosis和存储库备份到备份tarball,然后在空白系统上进行恢复和测试,以确保在完全服务器故障的情况下我可以快速运行新系统。

我有两个目录使用

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

然后加紧

在我干净安装的机器上,我已经解压缩了tarball并完成了

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

进入这两个目录并执行git log会显示历史记录。

但是这并没有提交给新服务器。但是做git push origin master并不起作用,它声称是最新的。

但是,任何尝试从我的新服务器进行克隆的尝试都会失败,因为正确地说,repo实际上并不是服务器的一部分。

那我该怎么办呢?我一直无法找到关于在本网站或任何其他网站上恢复gitosis的答案。

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

另外做git push gitosis @ localhost:gitosis-admin origin / master似乎推,但是如果我然后在一个单独的目录中做一个gitosis-admin的克隆,然后做git log然后我就有了初始化条目。

2 个答案:

答案 0 :(得分:0)

如果您正在使用ssh地址,如“Setting up git securely and easily using gitosis”中所述,您需要确保gitosis管理员帐户在您的第一台服务器上具有正确的~gitosis/.ssh/authorized_keys,以及公共和私钥最初用于克隆gitosis-admin.git repo。

总结以下评论:

  • 在服务器上安装gitosis
  • 确保您的ssh守护程序正在使用所述服务器
  • 生成一个新密钥(仍然在服务器上),这将允许您克隆gitosis-admin repo
  • 解压缩本地工作站上的备份回购
  • git push --force您的本地gitosis-admin回到服务器上,使用新帐户和新密钥。

答案 1 :(得分:0)

由VonC解决,指出(a)我需要在我做任何事情之前初始化gitosis,以及(b)推动工作需要--force命令。