Especially useful to backup dynamic environments where people are adding new repos all the time, avoids having to maintain configurations as finds and iterates all non-fork repos by default
Can't use Terraform to dynamically create these backups because a simple commented/deleted code mistake would bypass prevent_destroy and delete your backup repos as well as your originals!
Cron this script as per your preferred backup schedule
If no repos are given, iterates all non-fork repos for the current user or GitHub organization
Each repo will have the same name in AWS as it does on GitHub
For source GitHub accounts, requires:
- \$GITHUB_TOKEN
- \$GITHUB_ORGANIZATION, \$GITHUB_USER or else infers owner of the \$GITHUB_TOKEN
For AWS CodeCommit requires:
- \$AWS_DEFAULT_REGION
- AWS Credentials:
- AWS CLI configured with CodeCommit full access to create repositories (\$AWS_PROFILE, \$AWS_ACCESS_KEY_ID, \$AWS_SECRET_ACCESS_KEY etc.)
- \$AWS_GIT_USER and \$AWS_GIT_PASSWORD
or
- Python Pip git-remote-codecommit module to be installed to use AWS CLI credentials
In a GitHub Organization, only repos the user can read will be mirrored, others won't be returned in the list of GitHub repos to even try (as an outside collaborator user)
If \$CLEAR_CACHE_GITHUB_MIRROR is set to any value, deletes the /tmp cache and uses a fresh clone mirror. This can sometimes clear push errors.
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="[<repo1> <repo2> <repo3> ...]"
check_env_defined "GITHUB_TOKEN"
check_env_defined "AWS_DEFAULT_REGION"
help_usage "$@"
#min_args 1 "$@"
timestamp "Starting GitHub to AWS CodeCommit mirroring"
echo >&2
user="${GITHUB_USER:-$(get_github_user)}"
owner="${GITHUB_ORGANIZATION:-$user}"
if is_blank "$owner";then
die "Failed to determine GitHub owner"
fi
if[$# -gt 0];then
repos="$*"
else
timestamp "Getting list of all non-fork GitHub repos owned by '$owner'"