0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

githubのOrganizationアカウントにあるリポジトリをmirrorバックアップ

0
Last updated at Posted at 2016-09-26

準備

  1. githubのOrganizationアカウントの管理権限があるユーザでログインします。
  2. Edit profile -> Developer settings -> personal access tokenをクリック
  3. Generate New Tokenボタンをクリック
  4. スクリーンショット 2016-09-26 15.22.08.png
  5. tokenを生成し、控えておく
  6. 下のスクリプトに生成したTokenやログインIDを設定。
  7. スクリプトをバックアップ先のサーバの、バックアップリポジトリ保管ディレクトリへ保存
  8. cronなどお好きなツールで定期実行
# !/bin/sh

#####
#
# このシェルはjqコマンド使っています。
# yum -y install jq
# にてインストールをしてください。
#
# 動作概要
# 実行ディレクトリの直下にgithub organizationユーザのリポジトリのバックアップをとります。
# バックアップ方法は git clone --mirrorとしています。
# 直下にディレクトリが存在する場合は git fetch --allにて同期処理を行うようにしています。
#
# 使用方法
# バックアップ先のマシンのリポジトリバックアップディレクトリの直下にこのシェルを置いてください。
# 作成後に実行権与えていただければ実行可能になります。
# chmod 755 "このシェル".sh
#
# 変数のxxxxxxのところはそれぞれ適切なログインアカウントやtokenに書き換えてください
#####

BACKUP_REPOSDIR=`echo $(cd $(dirname $0) && pwd)`
LOGIN_NAME='xxxxxxxxxxxxxx'
GITHUB_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxx'
API_ROOT='api.github.com/orgs/xxxxx'
ORG_GITROOT_PATH='git@github.com:xxxxxxx'

# get repository list
curl https://${LOGIN_NAME}:${GITHUB_TOKEN}@${API_ROOT}/repos?per_page=1000 |
jq -r '.[].ssh_url' |
while read -r repo; do
  dir=`echo $repo | sed -e "s/${ORG_GITROOT_PATH}\///"`
  if [ -e $dir ]; then
    echo "${repo}"
    cd $dir
    git fetch --all
    cd ${BACKUP_REPOSDIR}
  else
    git clone --mirror "${repo}"
  fi
done
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?