Description: Backup all repositories belonging to a specific owner.
Author: AniMus
You must have a valid account on GitHub and you have to download and install the GitHub CLI (if you need more info about this cli tool follow this link). After the installation of the GitHub CLI you can check the installation running the following command:
animus@host:~$gh --version
You should see the version of the cli like shown below (at the time of writing the last version is 1.4.0 )
gh version 1.4.0 (2020-12-15)
https://github.com/cli/cli/releases/latest
After you need to authenticate the cli running the following command to start interactive setup of your credentials:
animus@host:~$gh auth login
Follow the directions on the screen to use your GitHub credentials in the GitHub CLI (you can use either the browser or an authentication token to authenticate you).
Run the script the defining the only two mandatory parameters owner and the backup directory
animus@host:~$repos.github.backup.sh -ow OWNER -dr DIRECTORY
You can run the script filtering with custom regular expressions repositories names (e.g. ^react*.) or branches name (e.g. ^((master)|(main)|(develop))$).
animus@host:~$repos.github.backup.sh -ow OWNER -dr DIRECTORY -rr "VALID REGEX" -br "VALID REGEX"
Display the help running:
animus@host:~$repos.github.backup.sh --help
You'll get help
usage: repos.github.backup.sh -ow OWNER -dr DIRECTORY
Backup one or more repositories hosted on GitHub in a local directory.
Options:
-ow, --owner Owner of repository
-dr, --directory Backup Directory
-rr, --reposRegex Regular expression to match repositories names to backup (default any)
-br, --branchesRegex Regular expression to match repositories branches to backup (default any)
-ps, --pageSize Page size of api paging (default 10)
--help Display this help and exit
Download all react repositories owned by Facebook:
repos.github.backup.sh --owner facebook -dr . -rr "^react.*" -br "^((master)|(main)|(develop))$"
Download all vscode repositories owned by Microsoft:
repos.github.backup.sh --owner microsoft -dr . -rr "^vscode..*" -br "^((master)|(main)|(develop))$"
Download all dart repositories owned by Google:
repos.github.backup.sh --owner google -dr . -rr "^dart..*" -br "^((master)|(main)|(develop))$"