How to backup your Github & Gitlab projects

Github Backup

Create an Access Token

Run the backup script

#!/bin/sh

dirname=github-backup-$(date "+%Y-%m-%d-%H-%M-%S")
mkdir "$dirname"
cd $dirname

#change these vars:
privateToken=YOUR_ACCESS_TOKEN
userName=YOUR_GITHUB_USERNAME

curl -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
done

echo Done! All files downloaded here: $(pwd)

Gitlab Backup

Create an Access Token

Run the backup script

#!/bin/sh

dirname=gitlab-backup-$(date "+%Y-%m-%d-%H-%M-%S")
mkdir "$dirname"
cd $dirname

privateToken=YOUR_ACCESS_TOKEN
userName=YOUR_GITLAB_USERNAME

curl --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
done

echo Done! All files downloaded here: $(pwd)

--

--

--

https://alexadam.dev/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Web development : At a glance

4 takeaways from The Things Virtual Conference 2020

Ingest any file as Parquet into your S3 data lake

Think twice before you use Durable Functions

https://t.co/Khw379ThML

How can you contribute to the Cosmos Ecosystem

GSoC in a Nutshell

Lazy Loading in Laravel

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
alex adam

alex adam

https://alexadam.dev/

More from Medium

Microsoft Teams channel Notification System — Rest API & Webhook

Future Schedules API by Aviation Edge — JSON REST Schedule API

Easy way to Remove Grab In windows dual boot with Linux.

(MySQL)如何得到Date Range之間的所有日子