Last active
March 13, 2022 15:07
-
-
Save thomd/92882a7650215a2c423aa0bd0e4ebc25 to your computer and use it in GitHub Desktop.
Backup all Github Repositories to AWS S3 (tested on maxOS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NOW := $(shell date +"%Y%m%d%H%M%S") | |
BUCKET := thomd/github/ | |
N_REPOS := $(shell gh repo list --source -L 200 | wc -l | sed 's/ //g') | |
N_GISTS := $(shell gh gist list -L 400 | wc -l | sed 's/ //g') | |
.PHONY: backup | |
backup: | |
@n=1; for repo in $$(gh repo list --source -L 200 --json name | jq -r '.[].name'); do echo "\033[0;90mcloning repository $${n}/$(N_REPOS):\033[0m $${repo}"; n=$$((n+1)); gh repo clone $${repo} thomd/$${repo} -- -q; done | |
@n=1; for gist in $$(gh gist list -L 400 | awk '{print $$1}'); do echo "\033[0;90mcloning gist $${n}/$(N_GISTS):\033[0m $${gist}"; n=$$((n+1)); gh gist clone $${gist} thomd/$${gist} -- -q; done | |
@tar -czf thomd_$(NOW).tar.gz thomd/ | |
@rm -fr thomd/ | |
@for tar in $$(ls *.tar.gz); do echo $${tar}; done | sort -rn | sed 1d | while read -r tar; do rm $${tar}; done | |
@aws s3 cp thomd_$(NOW).tar.gz "s3://$(BUCKET)thomd_$(NOW).tar.gz" | |
@aws s3 ls "s3://$(BUCKET)" | awk '{print $$4}' | sort -rn | sed 1,2d | while read -r f; do aws s3 rm "s3://$(BUCKET)$$f"; done | |
@aws s3 ls "s3://$(BUCKET)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment