GIT clone for external drive for backup

It's easy for me, I'm not from the command line ... We have GIT configured on our Windows network (using msysgit and GitExtensions). Each of us has our own repositories, and we click on the remote "bare" repository on one of our servers. All right.

I am trying to set up a scheduled task on a server that will clone a repository from drive C to an external drive (on F) - with some difficulty making it work. I can do this in GIT bash relatively easily, but I'm not sure how to save this in a batch file, which I can then execute.

What I still have:

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

I also tried the following for the last line:

 GIT CLONE C:\GIT\Repo1\ 

But this also does not work ... I am a bit stumped and will be grateful for the help. Drive C contains our bare repositories, and drive F is our external drive, which we change daily ...




A few answers here that were very helpful, thanks. My final answer is probably a combination of them, so there are points to indicate how to run a bash script and how to pull / push script.

It is necessary to combine them into work so that he is happy when various drives are changed and unloaded (i.e., clone the repository if it does not exist on the external drive, and then only pull the differences otherwise), but this should be feasible. Thanks to everyone.

+17
git windows backup
Dec 11 '09 at 11:10
source share
6 answers

Please note: git itself only perfectly copies the necessary changes to the cloned repository.

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

Ok, 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 a clone:

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

Now 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 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 this 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 tuned. So all your script should do is give out a git push backup . There is no need to discard the old backup many times.

An alternative could be rsync to do everything for you:

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

Custom add adds . Starting with version 1.5.4, "git remote add" accepts the "--mirror" parameter, which saves you from having to have "git config remote. Origin.mirror true", and from having to go through --mirror to "git push".

+26
Dec 11 '09 at 11:32
source share

You can always simply schedule bash.exe mybashbackupscript.sh

Anyway, in terms of windows:

 rmdir F:\GitClone /s /q mkdir -p F:\GitClone\Repo1 copy c:\GIT\Repo1\.git F:\GitClone\Repo1\.git 

git clone really does nothing more attractive than that.

edit: as someone else remarked, it is best to just create a new backup and just insert / extract. You will avoid any problems with .git :)

+4
Dec 11 '09 at 11:21
source share

Since the git command is a bit strange, you need to use call to execute any git commands from the batch file:

 rmdir F:\GitClone /s /q mkdir F:\GitClone CD /DF:\GitClone\ call GIT CLONE c/GIT/Repo1/ 
+4
Dec 11 '09 at 11:29
source share

Sorry, I cannot comment on posts, but I also thought about copying .git, but what happens if .git is copied during pull?

In any case, why copy all the material, how could you bring deltas from time to time?

Initialize backup: (in F: \ GitClone \ Repo1 is empty)

 git init git add remote origin /c/GIT/Repo1 

Then your “delta backup script” will simply do:

 cd /f/GitClone/Repo1 git fetch origin 
+1
Dec 11 '09 at 11:32
source share

Why do you delete the clone all the time? What is the point of cloning an existing repository when you just want to copy a file?

Just create a repo on an external drive (using git clone once) and then run its git pull .

0
Dec 11 '09 at 11:37
source share

Problem resolved:

 h: (flash drive) cd \ mkdir YourProject cd YourProject git init git remote add origin git@github.com:user/YourProject.git git remote add local C:\w\YourProject git pull origin master git push local master 
0
Mar 05 '13 at 12:43
source share



All Articles