Re: backup or mirror a repository
From: Dmitry Potapov <hidden>
Date: 2016-06-15 22:43:42
On Thu, Sep 27, 2007 at 11:27:06PM -0700, Junio C Hamano wrote:
The "git remote add --mirror" setup is about setting up the local repository _AS_ the backup of the remote. In other words, the contents come from the remote by fetching from it and safely kept away from disaster on the local side. And for that, "remote prune" is a perfect thing to do.
I have tried to do that but I am getting a warning:
$ git remote prune origin
Warning: unrecognized mapping in remotes.origin.fetch: +refs/*:refs/*
and no branch is removed.
I suspect that the change that introduced --mirror option for the 'add'
command did not adjust the prune procedure to handle the new situation
properly. Or is just me doing something wrong?
Anyway, because the official released git still does not have --mirror
and it could be difficult to convince the admin to use the bleading edge
version of Git for secure backup, I wrote a simple script instead, which
provides the same functionality but using the released version of Git.
Maybe, someone else finds it useful.
$ cat git-mirror
#!/bin/sh
usage() {
echo >&2 "Usage: $0 URL"
exit 1
}
set -e
test $# -eq 1 || usage
URL="$1"
# Initialize Git bare directory
git --bare init
# Initialize the mirror
git remote add origin "$URL"
git fetch
rmdir refs/heads
ln -s remotes/origin refs/heads
# Adding creating a script that will be run by cron
cat <<EOF > git-mirror-sync
cd "$PWD"
git fetch
git remote prune origin
EOF
chmod +x git-mirror-sync
# Adding git-mirror-sync to cron
echo "Please, add $PWD/git-mirror-sync to cron"
#########################################################
Dmitry