Skip to content

Instantly share code, notes, and snippets.

@gizmotronic
Last active June 14, 2018 10:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gizmotronic/5981def6cb7e07ad0abe to your computer and use it in GitHub Desktop.
Save gizmotronic/5981def6cb7e07ad0abe to your computer and use it in GitHub Desktop.
Mirror gitlab repository via post-receive
#!/bin/sh
BACKUPPATH="/path/to/backup/location"
REPOPATH=`dirname $0`
REPOPATH=`cd -P "${REPOPATH}/.."; pwd`
cd "${REPOPATH}"
REPONAME=`basename "${REPOPATH}"`
REPOPATH=`dirname "${REPOPATH}"`
REPOWNER=`basename "${REPOPATH}"`
mkdir -p "${BACKUPPATH}/${REPOWNER}"
BACKUPREPO="${BACKUPPATH}/${REPOWNER}/${REPONAME}"
if test ! -d "${BACKUPREPO}"
then
git init --quiet --bare "${BACKUPREPO}"
fi
if test -z `git remote | grep "backup"`
then
git remote add backup "${BACKUPREPO}"
fi
git push --quiet --force --all backup
git push --quiet --force --tags backup
while read old new ref
do
if test "${new}" = "0000000000000000000000000000000000000000"
then
branch=`expr "${ref}" : "refs/heads/\\(.*\\)"`
if test -n "${branch}" -a "${ref}" = "refs/heads/${branch}"
then
git push --quiet --force backup ":${branch}"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment