mirror of
https://github.com/That-Guy-Jack/github-bundle-backup.git
synced 2025-04-29 05:52:28 +00:00
Added ability to run orgs and users at the same time
This commit is contained in:
parent
25a701434e
commit
0d6725042a
44
cloneall.sh
44
cloneall.sh
@ -10,13 +10,14 @@ githubOrganization="<Your organiasation>"
|
|||||||
# Script configuration
|
# Script configuration
|
||||||
targetDir="./repos-$(date +"%Y-%m-%d")"
|
targetDir="./repos-$(date +"%Y-%m-%d")"
|
||||||
cloneOrgRepos=true
|
cloneOrgRepos=true
|
||||||
cloneUserRepos=false
|
cloneUserRepos=true
|
||||||
targetField="clone_url"
|
targetField="clone_url"
|
||||||
startDir="$(pwd)"
|
startDir="$(pwd)"
|
||||||
|
|
||||||
# Script
|
# Script
|
||||||
mkdir -p $targetDir
|
mkdir -p $targetDir
|
||||||
cd $targetDir
|
cd $targetDir
|
||||||
|
echo "startDir: $startDir"
|
||||||
echo "PWD: $(pwd)"
|
echo "PWD: $(pwd)"
|
||||||
|
|
||||||
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-organization-repositories
|
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-organization-repositories
|
||||||
@ -24,6 +25,28 @@ listOrgReposUrl="https://api.github.com/orgs/$githubOrganization/repos?per_page=
|
|||||||
if $cloneOrgRepos
|
if $cloneOrgRepos
|
||||||
then
|
then
|
||||||
orgRepositories=$(curl $listOrgReposUrl -u ${githubUser}:${githubToken} | jq -r .[].${targetField})
|
orgRepositories=$(curl $listOrgReposUrl -u ${githubUser}:${githubToken} | jq -r .[].${targetField})
|
||||||
|
echo "$orgRepositories"
|
||||||
|
mkdir -p "$startDir/$targetDir/$githubOrganization"
|
||||||
|
cd "$startDir/$targetDir/$githubOrganization"
|
||||||
|
for repository in $orgRepositories
|
||||||
|
do
|
||||||
|
printf "\nRepository found: $repository\n"
|
||||||
|
repo="${repository##*/}"
|
||||||
|
repo="${repo%.*}"
|
||||||
|
echo "$repo"
|
||||||
|
echo "$repository"
|
||||||
|
mkdir -p "$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
|
||||||
else
|
else
|
||||||
orgRepositories=""
|
orgRepositories=""
|
||||||
fi
|
fi
|
||||||
@ -33,14 +56,12 @@ listUserRepoUrl="https://api.github.com/user/repos?per_page=100&type=owner"
|
|||||||
if $cloneUserRepos
|
if $cloneUserRepos
|
||||||
then
|
then
|
||||||
userRepositories=$(curl $listUserRepoUrl -u ${githubUser}:${githubToken} | jq -r .[].${targetField})
|
userRepositories=$(curl $listUserRepoUrl -u ${githubUser}:${githubToken} | jq -r .[].${targetField})
|
||||||
else
|
echo "$userRepositories"
|
||||||
userRepositories=""
|
echo "PWD: $(pwd)"
|
||||||
fi
|
mkdir -p "$startDir/$targetDir/$githubUser"
|
||||||
|
cd "$startDir/$targetDir/$githubUser"
|
||||||
# Clone all repositories
|
for repository in $userRepositories
|
||||||
repositories="$orgRepositories $userRepositories"
|
do
|
||||||
for repository in $repositories
|
|
||||||
do
|
|
||||||
printf "\nRepository found: $repository\n"
|
printf "\nRepository found: $repository\n"
|
||||||
repo="${repository##*/}"
|
repo="${repository##*/}"
|
||||||
repo="${repo%.*}"
|
repo="${repo%.*}"
|
||||||
@ -57,7 +78,10 @@ do
|
|||||||
git bundle create ./$repo.bundle --all
|
git bundle create ./$repo.bundle --all
|
||||||
git bundle verify ./$repo.bundle
|
git bundle verify ./$repo.bundle
|
||||||
cd ../
|
cd ../
|
||||||
done
|
done
|
||||||
|
else
|
||||||
|
userRepositories=""
|
||||||
|
fi
|
||||||
|
|
||||||
cd "$startDir"
|
cd "$startDir"
|
||||||
zip -r -m -9 "repo-archive-$(date +"%Y-%m-%d").zip" "$targetDir"
|
zip -r -m -9 "repo-archive-$(date +"%Y-%m-%d").zip" "$targetDir"
|
20
readme.md
20
readme.md
@ -1,5 +1,23 @@
|
|||||||
|
# Script for making a backup of a user/organisations Github repos with commit history
|
||||||
|
|
||||||
|
This script allows a user to backup repos with commit history from organisations/users and compress them into a single zip archive
|
||||||
|
|
||||||
|
# Running the script
|
||||||
|
|
||||||
|
Dependancies:
|
||||||
|
```
|
||||||
|
jq git zip
|
||||||
|
```
|
||||||
|
1. Replace `<your access token>` with your access token from https://github.com/settings/tokens Token only needs repo and org read permisions.
|
||||||
|
2. Replace `<your github user>` with your github user and set `cloneUserRepos=` to `true` if your cloning a users repos or Replace `<Your organiasation>` with a org name and set `cloneOrgRepos=` to `true`. It is possible to set both to `true` this will clone both the user and the orgs repo into seperate folders in a single .zip
|
||||||
|
|
||||||
|
3. Run the script with you might need to set the script to executable with `chmod +x ./cloneall.sh`
|
||||||
|
```
|
||||||
|
./cloneall.sh
|
||||||
|
```
|
||||||
|
|
||||||
# Restore a repo from a bundle file
|
# Restore a repo from a bundle file
|
||||||
Borrowed from https://gist.github.com/xtream1101/fd79f3099f572967605fab24d976b179
|
Restore notes 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
|
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
|
1. Clone the repo from the bundle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user