备份github组织存储库和成员分叉的bash脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了备份github组织存储库和成员分叉的bash脚本相关的知识,希望对你有一定的参考价值。
A crude script to query the GitHub API for a given Organisation, and backup its repositories and associated members forks.
#!/bin/bash # # Crude script to backup an organisations repositories and its members forks. # # Name of organisation ORG="change" # Needed to talk to API USER="changeme" PASS="changeme" API="https://api.github.com" BACKUP_DIR="/data/github_backups" TSTAMP=`date "+%Y%m%d-%H%M"` GITCMD="git clone --mirror [email protected]:" #GITCMD="git clone --mirror git://github.com/" #GITCMD="git clone --mirror https://${USER}@github.com/" mkdir -p $BACKUP_DIR # crudely get list of repositories in the organisation echo "# getting list of repos..." REPOLIST=`curl --silent -u $USER:$PASS ${API}/orgs/${ORG}/repos -q | grep name | awk -F': "' '{print $2}' | sed -e 's/",//g'` # for each repository, backit and forks up for REPO in $REPOLIST; do # backup org repo echo "Backing up ${ORG}/${REPO}" TSTAMP=`date "+%Y%m%d-%H%M"`; ${GITCMD}${ORG}/${REPO}.git ${BACKUP_DIR}/${ORG}-${REPO}-${TSTAMP}.git tar zcf ${BACKUP_DIR}/${ORG}-${REPO}-${TSTAMP}.tar.gz ${BACKUP_DIR}/${ORG}-${REPO}-${TSTAMP}.git rm -rf ${BACKUP_DIR}/${ORG}-${REPO}-${TSTAMP}.git # backup forks echo "# getting list of forks..." FORKLIST=`curl --silent -u $USER:$PASS ${API}/repos/${ORG}/${REPO}/forks -q | grep login | awk -F': "' '{print $2}' | sed -e 's/",//g'` for F in $FORKLIST; do echo "+ Backing up fork $F/${REPO}" TSTAMP=`date "+%Y%m%d-%H%M"`; ${GITCMD}${F}/${REPO}.git ${BACKUP_DIR}/${F}-${REPO}-${TSTAMP}.git tar zcf ${BACKUP_DIR}/${F}-${REPO}-${TSTAMP}.tar.gz ${BACKUP_DIR}/${F}-${REPO}-${TSTAMP}.git rm -rf ${BACKUP_DIR}/${F}-${REPO}-${TSTAMP}.git done done # clean up echo "pruning archive" #find $BACKUP_DIR -name '*.tar.gz' -mtime +3 -exec rm -fv {} ; echo "Backup process completed"
以上是关于备份github组织存储库和成员分叉的bash脚本的主要内容,如果未能解决你的问题,请参考以下文章
使用 Bash 脚本中的个人访问令牌访问 Github 上的组织存储库