Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shell script to backup git repositories (and their HEAD branches) and tar.gz them
#!/bin/bash
# XXX: This shell script temporarily creates the ./$orga/$repo folder structure
# XXX: This shell script persistently creates the ./$orga/$repo.tar.gz structure
ROOT_FOLDER=$(cd "$(dirname "$0")"; pwd);
_backup_repository() {
orga="$1";
repo="$2";
branch="$3";
if [ "$branch" == "" ]; then
branch="master";
fi;
if [ ! -d "$ROOT_FOLDER/$orga/$repo" ]; then
cd "$ROOT_FOLDER";
mkdir -p "$ROOT_FOLDER/$orga/$repo";
git clone "https://github.com/$orga/$repo.git" "$ROOT_FOLDER/$orga/$repo";
fi;
if [ -d "$ROOT_FOLDER/$orga/$repo" ]; then
cd "$ROOT_FOLDER/$orga/$repo";
git checkout $branch;
git fetch origin $branch;
git reset --hard origin/$branch;
fi;
cd "$ROOT_FOLDER/$orga/";
tar czvf $repo.tar.gz ./$repo;
rm -rf ./$repo;
}
# OFFICIAL STUFF
_backup_repository "Artificial-Engineering" "lycheejs" "development";
_backup_repository "Artificial-Engineering" "lycheejs-bundle";
_backup_repository "Artificial-Engineering" "lycheejs-runtime";
_backup_repository "Artificial-Engineering" "lycheejs-guide";
_backup_repository "Artificial-Engineering" "lycheejs-future";
_backup_repository "Artificial-Engineering" "lycheejs-legacy";
_backup_repository "Artificial-Engineering" "lycheejs-library";
_backup_repository "Artificial-Engineering" "lycheejs-harvester";
_backup_repository "Artificial-Engineering" "lycheejs-website";
_backup_repository "Artificial-Engineering" "AE-CICD";
_backup_repository "Artificial-Engineering" "AE-github-scrumboard";
_backup_repository "Artificial-Engineering" "AE-github-todo";
_backup_repository "Artificial-Engineering" "AE-website" "gh-pages";
_backup_repository "Artificial-Engineering" "offgrid-browser";
_backup_repository "Artificial-Engineering" "node-sdl-runtime";
_backup_repository "Artificial-University" "adblock-proxy";
_backup_repository "Artificial-University" "AU-courses";
_backup_repository "Artificial-University" "AU-lecture-tool";
_backup_repository "Artificial-University" "AU-website" "gh-pages";
# POLYFILLR STUFF
_backup_repository "polyfillr" "polyfillr.github.io";
_backup_repository "polyfillr" "polyfillr-console";
_backup_repository "polyfillr" "polyfillr-components";
_backup_repository "polyfillr" "polyfillr-ecmascript";
_backup_repository "polyfillr" "polyfillr-framework";
# PRIVATE STUFF
_backup_repository "cookiengineer" ".vim";
_backup_repository "cookiengineer" "abs";
_backup_repository "cookiengineer" "cookiengineer.github.io";
_backup_repository "cookiengineer" "dotfiles";
_backup_repository "cookiengineer" "icon-webfont-exporter";
_backup_repository "cookiengineer" "printer-driver-dell1130";
_backup_repository "cookiengineer" "screencast-to-youtube";
_backup_repository "cookiengineer" "talks";
_backup_repository "cookiengineer" "unimatrix-zero";
_backup_repository "cookiengineer" "vim-explorer";
_backup_repository "cookiengineer" "random-experiments";
_backup_repository "cookiengineer" "lycheejs-experiments";
_backup_repository "cookiengineer" "lycheejs-prototyper";
_backup_repository "cookiengineer" "jsconf2014-slides";
# BOTS
_backup_repository "humansneednotapply" "dear-github-please-dont-delete-me";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.