备份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.
  1. #!/bin/bash
  2.  
  3. #
  4. # Crude script to backup an organisations repositories and its members forks.
  5. #
  6.  
  7. # Name of organisation
  8. ORG="change"
  9.  
  10. # Needed to talk to API
  11. USER="changeme"
  12. PASS="changeme"
  13.  
  14. API="https://api.github.com"
  15.  
  16. BACKUP_DIR="/data/github_backups"
  17. TSTAMP=`date "+%Y%m%d-%H%M"`
  18.  
  19. GITCMD="git clone --mirror [email protected]:"
  20. #GITCMD="git clone --mirror git://github.com/"
  21. #GITCMD="git clone --mirror https://${USER}@github.com/"
  22.  
  23. mkdir -p $BACKUP_DIR
  24.  
  25. # crudely get list of repositories in the organisation
  26. echo "# getting list of repos..."
  27. REPOLIST=`curl --silent -u $USER:$PASS ${API}/orgs/${ORG}/repos -q | grep name | awk -F': "' '{print $2}' | sed -e 's/",//g'`
  28.  
  29. # for each repository, backit and forks up
  30. for REPO in $REPOLIST; do
  31.  
  32. # backup org repo
  33. echo "Backing up ${ORG}/${REPO}"
  34. TSTAMP=`date "+%Y%m%d-%H%M"`;
  35. ${GITCMD}${ORG}/${REPO}.git ${BACKUP_DIR}/${ORG}-${REPO}-${TSTAMP}.git
  36. tar zcf ${BACKUP_DIR}/${ORG}-${REPO}-${TSTAMP}.tar.gz ${BACKUP_DIR}/${ORG}-${REPO}-${TSTAMP}.git
  37. rm -rf ${BACKUP_DIR}/${ORG}-${REPO}-${TSTAMP}.git
  38.  
  39. # backup forks
  40. echo "# getting list of forks..."
  41. FORKLIST=`curl --silent -u $USER:$PASS ${API}/repos/${ORG}/${REPO}/forks -q | grep login | awk -F': "' '{print $2}' | sed -e 's/",//g'`
  42. for F in $FORKLIST; do
  43. echo "+ Backing up fork $F/${REPO}"
  44. TSTAMP=`date "+%Y%m%d-%H%M"`;
  45. ${GITCMD}${F}/${REPO}.git ${BACKUP_DIR}/${F}-${REPO}-${TSTAMP}.git
  46. tar zcf ${BACKUP_DIR}/${F}-${REPO}-${TSTAMP}.tar.gz ${BACKUP_DIR}/${F}-${REPO}-${TSTAMP}.git
  47. rm -rf ${BACKUP_DIR}/${F}-${REPO}-${TSTAMP}.git
  48. done
  49.  
  50. done
  51.  
  52. # clean up
  53. echo "pruning archive"
  54. #find $BACKUP_DIR -name '*.tar.gz' -mtime +3 -exec rm -fv {} ;
  55.  
  56. echo "Backup process completed"

以上是关于备份github组织存储库和成员分叉的bash脚本的主要内容,如果未能解决你的问题,请参考以下文章

使用 Bash 脚本中的个人访问令牌访问 Github 上的组织存储库

sh 用于备份组织的所有GitHub存储库的Shell脚本

sh 一个简单的脚本,用于备份组织的GitHub存储库,wiki和问题。

从分叉存储库中发布来自 GitHub 操作的评论的解决方法

Github - 分叉一个私人仓库

网宿云云存储备份