git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: backup or mirror a repository

From
Dmitry Potapov <dpotapov@gmail.com>
Date
Oct 18, 2007, 05:32 UTC
Message-ID
<20071018053226.GA20588@dpotapov.dyndns.org>
In-Reply-To
<7vsl4zqp8l.fsf@gitster.siamese.dyndns.org>
On Thu, Sep 27, 2007 at 11:27:06PM -0700, Junio C Hamano wrote:
Show 5 quoted lines
> 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
Previous: Dan FarinaNext: Johannes Schindelin
Message 8 of 9 in “backup or mirror a repository”
  1. Dan FarinaSep 27, 2007
  2. Johannes SchindelinSep 27, 2007
  3. Dan FarinaSep 28, 2007
  4. Johannes SchindelinSep 28, 2007
  5. Dan FarinaSep 28, 2007
  6. Junio C HamanoSep 28, 2007
  7. Dan FarinaSep 28, 2007
  8. Dmitry PotapovOct 18, 2007
  9. Johannes SchindelinOct 30, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.