Last active
June 14, 2018 10:55
-
-
Save gizmotronic/5981def6cb7e07ad0abe to your computer and use it in GitHub Desktop.
Mirror gitlab repository via post-receive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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