Created
January 6, 2018 11:46
-
-
Save aibax/0865295d494a128f0e65fc1a182df3ac to your computer and use it in GitHub Desktop.
AWS CodeCommit のリポジトリを別のリージョンに移すシェルスクリプト
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 | |
# Requirements | |
# - AWS CLI | |
# - git | |
# - jq | |
REGION_FROM="us-east-1" # 移行元リージョン名 | |
REGION_TO="ap-northeast-1" # 移行先リージョン名 | |
echo "リモートリポジトリの移行を開始します" | |
echo "- 移行元リージョン : ${REGION_FROM}" | |
echo "- 移行先リージョン : ${REGION_TO}" | |
echo "\n" | |
# 移行元リポジトリの一覧を取得 | |
aws codecommit list-repositories --region ${REGION_FROM} | jq .repositories[].repositoryName | sed 's/"//g' > repositories | |
cat repositories | while read repository | |
do | |
echo "\033[0;32mリモートリポジトリを移行します - ${repository}\033[0;39m\n" | |
# | |
# 移行先リモートリポジトリの準備 | |
# | |
echo "\033[0;32m移行先リモートリポジトリを作成 - ${repository}\033[0;39m" | |
#aws codecommit delete-repository --repository-name ${repository} --region ${REGION_TO} # 作成前に削除する場合はコメントを外す | |
aws codecommit create-repository --repository-name ${repository} --region ${REGION_TO} | |
URL_FROM=`aws codecommit get-repository --repository-name ${repository} --region ${REGION_FROM} | jq .repositoryMetadata.cloneUrlSsh | sed 's/"//g'` | |
echo "\033[0;32m移行元リモートリポジトリ : ${URL_FROM}\033[0;39m" | |
URL_TO=`aws codecommit get-repository --repository-name ${repository} --region ${REGION_TO} | jq .repositoryMetadata.cloneUrlSsh | sed 's/"//g'` | |
echo "\033[0;32m移行先リモートリポジトリ : ${URL_TO}\033[0;39m" | |
echo "" | |
# | |
# リポジトリの移行 | |
# | |
echo "\033[0;32mgit clone --mirror ${URL_FROM}\033[0;39m" | |
rm -Rf ${repository}.git | |
git clone --mirror ${URL_FROM} | |
pushd ${repository}.git | |
echo "\033[0;32mgit remote add --mirror=push ${REGION_TO} ${URL_TO}\033[0;39m" | |
git remote add --mirror=push ${REGION_TO} ${URL_TO} | |
echo "\033[0;32mgit push ${REGION_TO}\033[0;39m" | |
git push ${REGION_TO} | |
popd | |
echo "\033[0;32mリモートリポジトリを移行しました - ${repository}\033[0;39m\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment