-
-
Save rikima/8863552 to your computer and use it in GitHub Desktop.
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 | |
| ORIGIN="serverA" | |
| MIRROR="serverB" | |
| SYNC_USER="git" | |
| ORIGIN_REPO_ROOT="/home/$SYNC_USER/repositories" | |
| MIRROR_REPO_ROOT="/home/$SYNC_USER/repositories" | |
| LOGFILE=$ORIGIN_REPO_ROOT/gitsync.log | |
| reponame=$(basename $(pwd)) | |
| echo "[`date +"%Y/%m/%d %H:%M:%S"`] ${reponame} sync start." >> ${LOGFILE} | |
| exists=`ssh $SYNC_USER@$MIRROR ls -l $MIRROR_REPO_ROOT/$reponame 2>>$LOGFILE | wc -l` | |
| if [ $exists != 0 ]; then | |
| echo "[`date +"%Y/%m/%d %H:%M:%S"`] mirror repository ${reponame} already exists. \"git push --mirror\" execute." >> ${LOGFILE} | |
| `git push --mirror $SYNC_USER@$MIRROR:$MIRROR_REPO_ROOT/$reponame >> $LOGFILE 2>&1` | |
| else | |
| echo "[`date +"%Y/%m/%d %H:%M:%S"`] mirror repository ${reponame} does not exist. \"git clone --mirror\" execute." >> ${LOGFILE} | |
| `ssh $SYNC_USER@$MIRROR "(cd $MIRROR_REPO_ROOT ; git clone --mirror $SYNC_USER@$ORIGIN:$ORIGIN_REPO_ROOT/$reponame >> $LOGFILE 2>&1)"` | |
| fi | |
| echo "[`date +"%Y/%m/%d %H:%M:%S"`] ${reponame} sync end." >> ${LOGFILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment