diff --git a/cloneall.sh b/cloneall.sh new file mode 100755 index 0000000..87fd386 --- /dev/null +++ b/cloneall.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# requires jq -> https://stedolan.github.io/jq/download/; +# create oath token -> https://github.com/settings/tokens; + +# GitHub configuration +githubToken="" +githubUser="" +githubOrganization="" + +# Script configuration +targetDir="./repos-$(date +"%Y-%m-%d")" +cloneOrgRepos=true +cloneUserRepos=false +targetField="clone_url" +startDir="$(pwd)" + +# Script +mkdir -p $targetDir +cd $targetDir +echo "PWD: $(pwd)" + +# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-organization-repositories +listOrgReposUrl="https://api.github.com/orgs/$githubOrganization/repos?per_page=100" +if $cloneOrgRepos +then + orgRepositories=$(curl $listOrgReposUrl -u ${githubUser}:${githubToken} | jq -r .[].${targetField}) +else + orgRepositories="" +fi + +# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-the-authenticated-user +listUserRepoUrl="https://api.github.com/user/repos?per_page=100&type=owner" +if $cloneUserRepos +then + userRepositories=$(curl $listUserRepoUrl -u ${githubUser}:${githubToken} | jq -r .[].${targetField}) +else + userRepositories="" +fi + +# Clone all repositories +repositories="$orgRepositories $userRepositories" +for repository in $repositories +do + printf "\nRepository found: $repository\n" + repo="${repository##*/}" + repo="${repo%.*}" + echo "$repo" + echo "$repository" + mkdir "$repo" + cd "$repo" + git clone --mirror "$repository" . + for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; + do + git branch --track ${branch#remotes/origin/} $branch || git branch + done + echo "PWD: $(pwd)" + git bundle create ./$repo.bundle --all + git bundle verify ./$repo.bundle + cd ../ +done + +cd "$startDir" +zip -r -m -9 "repo-archive-$(date +"%Y-%m-%d").zip" "$targetDir" \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..faf3b75 --- /dev/null +++ b/readme.md @@ -0,0 +1,23 @@ +# Restore a repo from a bundle file +Borrowed from https://gist.github.com/xtream1101/fd79f3099f572967605fab24d976b179 + +Here we will restore the repo from the bundle and create a new remote origin that will contain all brnaches and tags +1. Clone the repo from the bundle + ``` + git clone vuejs_vue.bundle + ``` +2. Get all the branches locally to be pushed up to your origin later (from: https://gist.github.com/grimzy/a1d3aae40412634df29cf86bb74a6f72) + ``` + git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done + git fetch --all + git pull --all + ``` +3. Create a new repo on your git server and update the origin of the local repo + ``` + git remote set-url origin git@github.com/xtream1101/test-backup.git + ``` +4. Push all branches and tags to the new remote origin + ``` + git push --all + git push --tags + ``` \ No newline at end of file