GIT克隆到外部驱动器进行备份 [英] GIT clone to external drive for backup

查看:83
本文介绍了GIT克隆到外部驱动器进行备份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说很简单,我不是一个命令行的人......我们在我们的Windows网络中使用了GIT(使用msysgit& GitExtensions)。我们每个人都有自己的存储库,并且我们推送到我们的一台服务器上的远程裸存储库。所有好的。

我试图在服务器上设置一个预定作业,它将C库中的存储库克隆到外部驱动器(F上) - 有一些困难得到这个工作。我可以很容易地在GIT bash中做到这一点,但我不知道如何将它保存到一个批处理文件中,然后我就可以处理它。



到目前为止我所拥有的:
$ b $ pre $ rmdir F:\GitClone / s / q
mkdir F:\GitClone
mkdir F:\GitClone\Repo1
CD / DF:\GitClone\Repo1\
GIT CLONE / c / GIT / Repo1 /

我也在最后一行尝试了以下内容:

  GIT CLONE C:\GIT\Repo1\ 

但这也行不通...我有点难住,希望得到一些帮助。 C驱动器包含我们裸露的存储库,F驱动器是我们每天更换的外部驱动器...




几个这里的答案非常有用,谢谢。我得到的答案可能是这些的组合,因此指出如何运行bash脚本以及如何编写拉/推脚本。

需要将这些功能集中在一起,以便在各种驱动器交换时非常高兴(例如,如果外部驱动器上不存在克隆存储库并且那么只有拉别的差异),但这应该是可行的。感谢所有人。

>

如果您希望定期更新repo的副本,请执行以下操作:创建裸仓库作为备份存储库,然后重复推送所有新更改(无需删除旧备份)。



好吧,让我们开始创建您的存储库

  $ cd / tmp 
$ mkdir myrepo&& cd myrepo
$ touch hi&& git add。 &安培;&安培; git commit -mbla

所以,这是您的存储库。现在我们创建一个克隆:

  $ cd / tmp 
$ mkdir backup&& cd备份
$ git --bare init
在/ tmp / backup /
中初始化的空Git存储库

现在,让我们设置您的常规备份回购... ...

$ $ $ $ $ $ $ cd $ tmp / myrepo
$ git remote add backup / tmp / backup
$ git config remote.backup.mirror true

然后将所有内容复制到备份中:

  $ git push backup 
计数对象:3,完成。
写入对象:100%(3/3),206字节,完成。
合计3(delta 0),重用0(delta 0)
开箱对象:100%(3/3),完成。
至/ tmp / backup
*°newbranch§master - > master

然后查看它是否有效:

  $ cd / tmp / backup 
$ git log
commit d027b125166ff3a5be2d7f7416893a012f218f82
作者:Niko Schwarz<niko.schwarzàgmail.com>
日期:星期五12月11日12:24:03 2009 +0100


Tada,你定了。因此,你所有的脚本需要做的是发行 git push backup 。完全不需要重复丢弃旧的备份。

另一种方法是,您可以 rsync 为你做这一切:

  rsync -av rsync://rsync.samba.org/ftp/解压/ rsync / dest / dir / 

用户Offby添加:自版本1.5.4,git remote add需要一个--mirror选项,这样既可以避免git config remote.origin.mirror true,也不必将-mirror传递给git push。

Go easy on me, I'm not much of a command line man... We have GIT set up within our windows network (using msysgit & GitExtensions). We each have our own repositories and we push to a remote 'bare' repository on one of our servers. All good.

I'm trying to set up a scheduled job on the server, which will clone a repository from the C drive to an external drive (on F) - having some difficulty getting this to work. I can do this in GIT bash relatively easily, but I'm not sure how to save this into a batch file that I can then scehdule.

What I have so far:

rmdir F:\GitClone /s /q
mkdir F:\GitClone
mkdir F:\GitClone\Repo1
CD /D F:\GitClone\Repo1\
GIT CLONE /c/GIT/Repo1/

I've also tried the following for the last line:

GIT CLONE C:\GIT\Repo1\

But this doesn't work either... I'm a little stumped and would appreciate some help. The C drive contains our bare repositories and the F drive being our external drive that we swap out daily...


Several answers here that have been very useful, thanks. My resulting answer is probably a combination of these, so points for pointing out how to run a bash script and how to script the pull/push.

Need to bring these together to work so that it's happy when various drives are swapped in and out (i.e. clone a repository if it doesn't exist on the external drive and then only pull the differences otherwise), but that should be doable. Thanks to all.

解决方案

Please note that git itself is excellent at copying only the needed changes to a cloned repository.

If you want a copy of your repo to be regularly updated, do this: You create a bare repository as a backup repository, and then repeatedly push all new changes there (no need to delete the old backup).

Ok, let's start by creating your repo

$ cd /tmp
$ mkdir myrepo && cd myrepo
$ touch hi && git add . && git commit -m "bla" 

So, this is your repository. Now we create the clone:

$ cd /tmp
$ mkdir backup && cd backup 
$ git --bare init
Initialized empty Git repository in /tmp/backup/

Now, let's set up your repo for regular backups …

$ cd /tmp/myrepo
$ git remote add backup /tmp/backup
$ git config remote.backup.mirror true

Then copy everything to the backup:

$ git push backup
Counting objects: 3, done.
Writing objects: 100% (3/3), 206 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /tmp/backup
 * °new branch§      master -> master

And see if it worked:

$ cd /tmp/backup
$ git log
commit d027b125166ff3a5be2d7f7416893a012f218f82
Author: Niko Schwarz <niko.schwarzàgmail.com>
Date:   Fri Dec 11 12:24:03 2009 +0100

    hi

Tada, you're set. Therefore, all your script needs to do is to issue git push backup. There's exactly no need to repeatedly throw away the old backup.

The alternative is you can have rsync do it all for you:

rsync -av rsync://rsync.samba.org/ftp/unpacked/rsync /dest/dir/

User Offby adds: Since version 1.5.4, "git remote add" takes a "--mirror" option, which saves you both from having to "git config remote.origin.mirror true", and from having to pass --mirror to "git push".

这篇关于GIT克隆到外部驱动器进行备份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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