Created
January 6, 2012 13:42
-
-
Save mhoyer/1570668 to your computer and use it in GitHub Desktop.
git-backup with auto generated backup remote
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 | |
GIT_MAIN_ROOT=/tmp/git-backup/git.repos | |
GIT_BACKUP_ROOT=/tmp/git-backup/git.repos.bak | |
GIT_BACKUP_REMOTE=backup | |
###### | |
echo \>\>\> Backing up to $GIT_BACKUP_ROOT | |
if [[ `git remote | grep $GIT_BACKUP_REMOTE` == '' ]] ; then | |
LOCAL_ORIGIN_PUSH_PATH=`git remote show -n origin | grep -e 'Push URL' | sed 's/.*URL:\s//'` | |
LOCAL_ORIGIN_PUSH_PATH_REL=${LOCAL_ORIGIN_PUSH_PATH/${GIT_MAIN_ROOT}/} | |
REMOTE_BACKUP_PUSH_PATH=$GIT_BACKUP_ROOT$LOCAL_ORIGIN_PUSH_PATH_REL | |
echo Backup remote \'$GIT_BACKUP_REMOTE\' not found. Creating new remote entry. | |
if [[ ! -d $REMOTE_BACKUP_PUSH_PATH ]] ; then | |
git init --bare $REMOTE_BACKUP_PUSH_PATH | |
fi | |
git remote add --mirror=push $GIT_BACKUP_REMOTE $REMOTE_BACKUP_PUSH_PATH | |
fi | |
git push $GIT_BACKUP_REMOTE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment