Backup Git repository from Xcode server

0

I have a OSX server with the Xcode service activated. The server hosts multiple git repositories, git is installed automatically by the service Xcode server.

I use Time Machine, but the problem is that I do not have the backup of each repository, but only a backup of the entire server.

Can I still see the repositories in the Time Machine backup, or is there some easier command in git that allows me to take backups?

Mattia Lancieri

Posted 2014-12-23T10:47:13.677

Reputation: 103

But if you open the Time Machine folder on the Time Machine drive, you can see all actual folders that were backed up from the server. You'll have access to each bare Git reposititory then, too, no? As for Git backups, see git archive: http://git-scm.com/docs/git-archive

– slhck – 2014-12-23T10:53:27.593

git archive looks perfect, thanks I tried it on the branch "master", but there is a way to run a zip for each branch? – Mattia Lancieri – 2014-12-23T12:48:25.230

Answers

1

When you open your Time Machine backup folder on the Time Machine volume, you can still see each individual directory, so wherever your Git repositories are stored as bare repos, you will be able to find and copy them.

You can also archive a Git repository with the git archive command.

git archive -o archive.zip master

If you want to do that for all branches, you could do something like:

for branch in $(git for-each-ref --format='%(refname)' refs/heads/); do
    git archive -o "${branch##*/}.zip" $branch
done

The substitution ${branch##*/} will convert refs/heads/master to master by stripping the longest match of */ from the beginning of the string.

This is inspired by a Stack Overflow question about iterating through branches.

slhck

Posted 2014-12-23T10:47:13.677

Reputation: 182 472

the variable $ branch includes the full path (ex: "refs/heads/master"), so I performed a substring git archive -o "${branch:11}.zip" $branch. I do not know if there is any better way .... – Mattia Lancieri – 2014-12-24T09:50:47.270

Ah, perhaps ${branch##*/} is what you want. See my updated post! – slhck – 2014-12-24T10:11:29.880