Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexadam/repo-backup
Backup all Github & Gitlab repositories as .zip files
https://github.com/alexadam/repo-backup
backup backup-script backup-solution backup-tool backup-utility backups bash bash-script github gitlab project repository
Last synced: about 1 month ago
JSON representation
Backup all Github & Gitlab repositories as .zip files
- Host: GitHub
- URL: https://github.com/alexadam/repo-backup
- Owner: alexadam
- License: mit
- Created: 2020-07-15T08:36:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-15T12:49:47.000Z (over 4 years ago)
- Last Synced: 2024-08-13T07:15:57.821Z (5 months ago)
- Topics: backup, backup-script, backup-solution, backup-tool, backup-utility, backups, bash, bash-script, github, gitlab, project, repository
- Language: Shell
- Homepage:
- Size: 791 KB
- Stars: 25
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - alexadam/repo-backup - Backup all Github & Gitlab repositories as .zip files (Shell)
README
# repo-backup
Backup all Github & Gitlab repositories as .zip files
## Github Backup
### Create an Access Token
On github.com, go to your profile -> Settings -> Developer Settings -> Personal access tokens
Click on Generate a personal access token
**Name**: *backup* (it doesn't matter)
**Scopes**: *repo* & *read:user*Then click on Generate token
![alt github.png](https://github.com/alexadam/repo-backup/blob/master/screenshots/github.png?raw=true)
### Run the backup script
After the token is generated, paste it in the script below:
```sh
#!/bin/shdirname=github-backup-$(date "+%Y-%m-%d-%H-%M-%S")
mkdir "$dirname"
cd $dirname#change these vars:
privateToken=YOUR_ACCESS_TOKEN
userName=YOUR_GITHUB_USERNAMEcurl -H "Accept: application/vnd.github.nebula-preview+json" \
-H "Authorization: token $privateToken" \
"https://api.github.com/user/repos?visibility=all&affiliation=owner&per_page=200" \
| jq -r '.[] | .name' \
| while IFS= read projectName; do
curl -H "Authorization: token $privateToken" -H "Accept: application/vnd.github.v3.raw" -L \
"https://api.github.com/repos/$userName/$projectName/zipball" --output $projectName.zip
doneecho Done! All files downloaded here: $(pwd)
```Then run the script with `sh github.sh` or `./github.sh` (`chmod +x github.sh` might be needed)
## Gitlab Backup
### Create an Access Token
On gitlab.com, go to your profile -> Settings -> Access Tokens and create a new Access Token
**Name**: *backup* (it doesn't matter)
**Expires at**: tomorrow (or later, if you want to reuse it)
**Scopes**: *read_api* & *read_repository*Then click on Create personal access token
![alt gitlab.png](https://github.com/alexadam/repo-backup/blob/master/screenshots/gitlab.png?raw=true)
### Run the backup script
After the token is generated, paste it in the script below:
```sh
#!/bin/shdirname=gitlab-backup-$(date "+%Y-%m-%d-%H-%M-%S")
mkdir "$dirname"
cd $dirnameprivateToken=YOUR_ACCESS_TOKEN
userName=YOUR_GITLAB_USERNAMEcurl --header "Private-Token: $privateToken" "https://gitlab.com/api/v4/users/$userName/projects" \
| jq -r '.[] | .id, .name' \
| while IFS= read projectId; read projectName; do
curl --header "Private-Token: $privateToken" "https://gitlab.com/api/v4/projects/$projectId/repository/archive.zip" --output $projectName.zip
doneecho Done! All files downloaded here: $(pwd)
```Then run the script with `sh gitlab.sh` or `./gitlab.sh` (`chmod +x gitlab.sh` might be needed)