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
40
cloneall.sh
40
cloneall.sh
@ -10,13 +10,14 @@ githubOrganization="<Your organiasation>"
|
||||
# Script configuration
|
||||
targetDir="./repos-$(date +"%Y-%m-%d")"
|
||||
cloneOrgRepos=true
|
||||
cloneUserRepos=false
|
||||
cloneUserRepos=true
|
||||
targetField="clone_url"
|
||||
startDir="$(pwd)"
|
||||
|
||||
# Script
|
||||
mkdir -p $targetDir
|
||||
cd $targetDir
|
||||
echo "startDir: $startDir"
|
||||
echo "PWD: $(pwd)"
|
||||
|
||||
# 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
|
||||
then
|
||||
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
|
||||
orgRepositories=""
|
||||
fi
|
||||
@ -33,13 +56,11 @@ 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
|
||||
echo "$userRepositories"
|
||||
echo "PWD: $(pwd)"
|
||||
mkdir -p "$startDir/$targetDir/$githubUser"
|
||||
cd "$startDir/$targetDir/$githubUser"
|
||||
for repository in $userRepositories
|
||||
do
|
||||
printf "\nRepository found: $repository\n"
|
||||
repo="${repository##*/}"
|
||||
@ -58,6 +79,9 @@ do
|
||||
git bundle verify ./$repo.bundle
|
||||
cd ../
|
||||
done
|
||||
else
|
||||
userRepositories=""
|
||||
fi
|
||||
|
||||
cd "$startDir"
|
||||
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
|
||||
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
|
||||
1. Clone the repo from the bundle
|
||||
|
Loading…
x
Reference in New Issue
Block a user