├── .editorconfig ├── LICENSE ├── README.md ├── .gitignore └── backup.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2018 Eugene Obrezkov 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Backup My GitHub Profile 2 | 3 | _Clones all your GitHub public repositories to your machine_ 4 | 5 | 6 | 7 | ## Prerequisites 8 | 9 | - curl 10 | - jq 11 | 12 | ## Using 13 | 14 | Before starting the script, you need to generate personal access token on GitHub (**with full repo access**). 15 | Follow this guide - [link](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line) 16 | 17 | Afterwards, navigate to the folder, where you want to store repos: 18 | 19 | ```bash 20 | mkdir -p /some/path/to/folder/with/backups 21 | cd /some/path/to/folder/with/backups 22 | ``` 23 | 24 | Run the script: 25 | 26 | ```bash 27 | bash <(curl -s https://raw.githubusercontent.com/ghaiklor/backup-my-github/master/backup.sh) 28 | ``` 29 | 30 | ## License 31 | 32 | [DWTFYWT](./LICENSE) 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 2 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 3 | 4 | # User-specific stuff 5 | .idea/**/workspace.xml 6 | .idea/**/tasks.xml 7 | .idea/**/dictionaries 8 | .idea/**/shelf 9 | 10 | # Sensitive or high-churn files 11 | .idea/**/dataSources/ 12 | .idea/**/dataSources.ids 13 | .idea/**/dataSources.local.xml 14 | .idea/**/sqlDataSources.xml 15 | .idea/**/dynamic.xml 16 | .idea/**/uiDesigner.xml 17 | .idea/**/dbnavigator.xml 18 | 19 | # Gradle 20 | .idea/**/gradle.xml 21 | .idea/**/libraries 22 | 23 | # CMake 24 | cmake-build-debug/ 25 | cmake-build-release/ 26 | 27 | # Mongo Explorer plugin 28 | .idea/**/mongoSettings.xml 29 | 30 | # File-based project format 31 | *.iws 32 | 33 | # IntelliJ 34 | out/ 35 | 36 | # mpeltonen/sbt-idea plugin 37 | .idea_modules/ 38 | 39 | # JIRA plugin 40 | atlassian-ide-plugin.xml 41 | 42 | # Cursive Clojure plugin 43 | .idea/replstate.xml 44 | 45 | # Crashlytics plugin (for Android Studio and IntelliJ) 46 | com_crashlytics_export_strings.xml 47 | crashlytics.properties 48 | crashlytics-build.properties 49 | fabric.properties 50 | 51 | # Editor-based Rest Client 52 | .idea/httpRequests 53 | 54 | # Misc 55 | .idea 56 | -------------------------------------------------------------------------------- /backup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | RESET_COLOR="\\033[0m" 6 | RED_COLOR="\\033[0;31m" 7 | GREEN_COLOR="\\033[0;32m" 8 | BLUE_COLOR="\\033[0;34m" 9 | 10 | function reset_color() { 11 | echo -e "${RESET_COLOR}\\c" 12 | } 13 | 14 | function red_color() { 15 | echo -e "${RED_COLOR}\\c" 16 | } 17 | 18 | function green_color() { 19 | echo -e "${GREEN_COLOR}\\c" 20 | } 21 | 22 | function blue_color() { 23 | echo -e "${BLUE_COLOR}\\c" 24 | } 25 | 26 | ### ----- ### 27 | ### Hello ### 28 | ### ----- ### 29 | blue_color 30 | echo " " 31 | echo " Backup My GitHub " 32 | echo " by @ghaiklor " 33 | echo " " 34 | echo "This script will download all your repositories from provided username to your machine" 35 | echo "It will prompt you for your username account and personal access token" 36 | echo "To generate token, please, refer this guide - https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line" 37 | echo "Make sure, that your token has full access to repo scope!" 38 | reset_color 39 | 40 | ### -------------- ### 41 | ### Check for curl ### 42 | ### -------------- ### 43 | if ! [ "$(command -v curl)" ]; then 44 | red_color 45 | echo "You don't have installed curl" 46 | exit 1 47 | else 48 | green_color 49 | echo "curl is present on your machine, continue..." 50 | fi 51 | reset_color 52 | 53 | ### ------------ ### 54 | ### Check for jq ### 55 | ### ------------ ### 56 | if ! [ "$(command -v jq)" ]; then 57 | red_color 58 | echo "You don't have installed jq" 59 | exit 1 60 | else 61 | green_color 62 | echo "jq is present on your machine, continue..." 63 | fi 64 | reset_color 65 | 66 | ### ---------------------- ### 67 | ### Prompt for credentials ### 68 | ### ---------------------- ### 69 | green_color 70 | echo 71 | read -r -p "What is your username on GitHub: " GITHUB_USERNAME 72 | read -r -p "What is your personal access token: " GITHUB_TOKEN 73 | echo 74 | reset_color 75 | 76 | ### ------------------ ### 77 | ### Clone Repositories ### 78 | ### ------------------ ### 79 | green_color 80 | read -r -n 1 -p "Do you want to clone repositories [Y/n]: " answer 81 | echo 82 | if [ "${answer}" != "n" ]; then 83 | blue_color 84 | repository_count=$(curl -XGET -s https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@api.github.com/users/"${GITHUB_USERNAME}" | jq -c --raw-output ".public_repos") 85 | repositories=$(curl -XGET -s https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@api.github.com/users/"${GITHUB_USERNAME}"/repos?per_page="${repository_count}" | jq -c --raw-output ".[].ssh_url") 86 | 87 | for repository in ${repositories}; do 88 | echo "Cloning ${repository}..." 89 | git clone --quiet "${repository}" 90 | done 91 | 92 | green_color 93 | echo "All your ${repository_count} repositories are successfully cloned in current directory" 94 | echo 95 | reset_color 96 | fi 97 | 98 | ### ---------------- ### 99 | ### Download Archive ### 100 | ### ---------------- ### 101 | green_color 102 | read -r -n 1 -p "Do you want to download your repositories as an archive (master branch) [Y/n]: " answer 103 | echo 104 | if [ "${answer}" != "n" ]; then 105 | blue_color 106 | repository_count=$(curl -XGET -s https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@api.github.com/users/"${GITHUB_USERNAME}" | jq -c --raw-output ".public_repos") 107 | repositories=$(curl -XGET -s https://"${GITHUB_USERNAME}":"${GITHUB_TOKEN}"@api.github.com/users/"${GITHUB_USERNAME}"/repos?per_page="${repository_count}" | jq -c --raw-output ".[].name") 108 | 109 | for repository in ${repositories}; do 110 | echo "Downloading ${repository}.tar.gz..." 111 | curl -L -s -o ${repository}.tar.gz https://github.com/${GITHUB_USERNAME}/${repository}/archive/master.tar.gz 112 | done 113 | 114 | green_color 115 | echo "All your ${repository_count} repositories are successfully downloaded in current directory" 116 | echo 117 | reset_color 118 | fi 119 | 120 | ### ------ ### 121 | ### Footer ### 122 | ### ------ ### 123 | green_color 124 | echo "Everything is done, thanks for having me :)" 125 | reset_color 126 | --------------------------------------------------------------------------------