First commit

This commit is contained in:
Jack 2023-06-26 14:35:53 +01:00
parent 9b6c519014
commit 25a701434e
2 changed files with 86 additions and 0 deletions

63
cloneall.sh Executable file
View File

@ -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="<your access token>"
githubUser="<your github user>"
githubOrganization="<Your organiasation>"
# 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"

23
readme.md Normal file
View File

@ -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
```