Skip to content

Professional solution for automatic cloning and backup of GitHub repositories and gists with enhanced reliability

License

Notifications You must be signed in to change notification settings

smartlegionlab/github_repos_backup_tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GitHub Repositories Backup Tools v0.9.1

GitHub top language GitHub release (latest by date) GitHub

Professional solution for automatic cloning and backup of GitHub repositories and gists with enhanced reliability


πŸ”₯ Key Features

  • Complete Backup - Clone both public and private repositories/gists
  • Smart Update System - Existing clones are updated via git pull
  • Resilient Retry Mechanism - 5 automatic retries for failed operations
  • Archive Support - Create compressed ZIP archives
  • System Control - Option to shutdown/reboot after completion
  • Real-time Monitoring - Improved progress bar with statistics
  • Cross-platform - Works on Linux and Termux (Android)

🚨 Important Notice

  • Added new --reboot flag that performs system reboot after completion
  • Made --reboot and --shutdown mutually exclusive using argparse group
  • Added reboot() method similar to shutdown() but for system restart
  • Changed the priority of receiving and checking information when initializing the application
  • Fixed incorrect display of some user interface elements

πŸš€ Quick Start Guide

1. Installation

git clone https://github.com/smartlegionlab/github_repos_backup_tools.git
cd github_repos_backup_tools

2. Configuration

Create .config.ini file:

[github]
token = your_github_token_here

3. Generate GitHub Token

  1. Visit GitHub Tokens
  2. Select permissions:
    • βœ… repo (full repository access)
    • βœ… gist (gist access)
  3. Generate and copy token

4. SSH Setup (Required)

# Generate SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"

# Add to ssh-agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# Add to GitHub account
cat ~/.ssh/id_ed25519.pub  # Copy this output
# Paste at https://github.com/settings/keys

# Verify connection
ssh -T git@github.com

πŸ’» Usage Options

Command Description
-r Clone all repositories
-g Clone all gists
--archive Create compressed backup archive
--verbose Show detailed debug output
--shutdown Shutdown computer after completion
--reboot Restart computer after completion

Common Command Combinations:

# Basic backup
python app.py -r -g

# Backup with archive creation
python app.py -r --archive

# Full backup with shutdown
python app.py -r -g --shutdown

# Debug mode
python app.py -g --verbose

πŸ“‚ File Structure

Backups are organized in your home directory:

~/
└── [username]_github_backup/
    β”œβ”€β”€ repositories/  # All cloned repositories
    β”œβ”€β”€ gists/        # All cloned gists
 [username]_github_backup.zip    # Created when using --archive

πŸ”§ Technical Details

  • Retry Logic: 5 attempts for each clone/update operation
  • Timeout: 20 seconds per git operation
  • Error Handling: Automatic cleanup of failed clones
  • Progress Tracking: Real-time visual feedback
  • System Integration: Supports shutdown/reboot commands

❓ Frequently Asked Questions

Q: How to cancel scheduled shutdown?
A: Use shutdown -c (Linux) or shutdown /a (Windows)

Q: Where are backups stored?
A: In ~/[your_username]_github_backup/

Q: How to update existing clones?
A: Just run the tool again - it automatically does git pull

πŸ“ Changelog

v0.9.1 Updates:

  • Added new --reboot flag that performs system reboot after completion
  • Made --reboot and --shutdown mutually exclusive using argparse group
  • Added reboot() method similar to shutdown() but for system restart
  • Changed the priority of receiving and checking information when initializing the application
  • Fixed incorrect display of some user interface elements

Author: A.A. Suvorov
License: BSD 3-Clause "New" or "Revised" License
Support: Open issue on GitHub

Example output without using the --verbose flag:

python app.py -r -g

************************************************************************************************************************
------------------------------------------- Github Repositories Backup Tools -------------------------------------------
------------------------------------------------------------------------------------------------------------------------

Getting a token from a .config.ini file: βœ…

Checking the token for validity:
Token is valid: βœ…

Getting user login:
βœ… Login: login

Parsing arguments:

Clone repositories: βœ…
Clone gists: βœ…
Make archive: ⚠
Shutdown: ⚠
Reboot: βœ…
Verbose: ⚠

Forming a path to the directory:
βœ… Path: /home/user/#_github_backup

------------------------------------------------------------------------------------------------------------------------
------------------------------------------------ Cloning repositories:  ------------------------------------------------
------------------------------------------------------------------------------------------------------------------------

Target directory: /home/user/#_github_backup/repositories
------------------------------------------------------------------------------------------------------------------------
Getting repositories:

-------------------------
βœ… Found 248 repositories.
-------------------------

[################################################--] 97.98% | 243/248 | Failed: 9 | Cloning: repo243

Example output when using the --verbose flag:

python app -r -g --verbose

************************************************************************************************************************
------------------------------------------- Github Repositories Backup Tools -------------------------------------------
------------------------------------------------------------------------------------------------------------------------

Getting a token from a .config.ini file: βœ…

Checking the token for validity:
Token is valid: βœ…

Getting user login:
βœ… Login: login

Parsing arguments:

Clone repositories: βœ…
Clone gists: βœ…
Make archive: ⚠
Shutdown: ⚠
Reboot: βœ…
Verbose: βœ…

Forming a path to the directory:
βœ… Path: /home/user/#_github_backup

------------------------------------------------------------------------------------------------------------------------
------------------------------------------------ Cloning repositories:  ------------------------------------------------
------------------------------------------------------------------------------------------------------------------------

Target directory: /home/user/#_github_backup/repositories
------------------------------------------------------------------------------------------------------------------------
Getting repositories:

-------------------------
βœ… Found 3 repositories.
-------------------------

---------------------------------------
1/3/0: Cloning: login/repo1
---------------------------------------
βœ… Repository updated successfully: 
/home/user/#_github_backup/repositories/#/repo1
------------------------------------------------
2/3/0: Cloning: login/repo2
------------------------------------------------
⚠ Pull operation timed out: 
/home/user/#_github_backup/repositories/#/repo2
⚠ Pull failed. Removing and re-cloning: 
/home/user/#_github_backup/repositories/#/repo2
⚠ Clone operation timed out: 
/home/user/#_github_backup/repositories/#/repo2
⚠ Removing incomplete repositories: 
/home/user/#_github_backup/repositories/#/repo2
---------------------------------------------------------------
3/3/1: Cloning: login/repo3
---------------------------------------------------------------
⚠ Pull operation timed out: 
/home/user/#_github_backup/repositories/#/repo3
⚠ Pull failed. Removing and re-cloning: 
/home/user/#_github_backup/repositories/#/repo3
βœ… Repository cloned successfully: 
/home/user/#_github_backup/repositories/#/repo3
------------------------------------------------------------------------------------------------------------------------

-----------------------------------------
Retrying failed repositories: 1 remaining
-----------------------------------------

------------------------------------------------------------
1/1/1: Retrying: login/repo2
------------------------------------------------------------
βœ… Repository cloned successfully: 
/home/user/#_github_backup/repositories/#/repo2

------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------- Cloning gists:  ----------------------------------------------------
------------------------------------------------------------------------------------------------------------------------

Target directory: /home/user/#_github_backup/gists
------------------------------------------------------------------------------------------------------------------------
Getting gists:

------------------
βœ… Found 3 gists.
------------------

--------------------------------------------------
1/3/0: Cloning: name1
--------------------------------------------------
βœ… Repository updated successfully: 
/home/user/#_github_backup/gists/name1
--------------------------------------------------
2/3/0: Cloning: name2
--------------------------------------------------
⚠ Pull operation timed out: 
/home/user/#_github_backup/gists/name2
⚠ Pull failed. Removing and re-cloning: 
/home/user/#_github_backup/gists/name2
⚠ Clone operation timed out: 
/home/user/#_github_backup/gists/name2
⚠ Removing incomplete gists: 
/home/user/#_github_backup/gists/name2
--------------------------------------------------
3/3/1: Cloning: name3
--------------------------------------------------
⚠ Pull operation timed out: 
/home/user/#_github_backup/gists/name3
⚠ Pull failed. Removing and re-cloning: 
/home/user/#_github_backup/gists/name3
βœ… Repository cloned successfully: 
/home/user/#_github_backup/gists/name3
------------------------------------------------------------------------------------------------------------------------

----------------------------------
Retrying failed gists: 1 remaining
----------------------------------

------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------
1/1/1: Retrying: name2
-------------------------------------------------
βœ… Repository cloned successfully: 
/home/user/#_github_backup/gists/name2
------------------------------------------------------------------------------------------------------------------------
------------------------------------------ https://github.com/smartlegionlab/ ------------------------------------------
------------------------------------------ Copyright Β© 2018-2025, A.A. Suvorov -----------------------------------------
************************************************************************************************************************

Disclaimer of liability:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright:

--------------------------------------------------------
Licensed under the terms of the BSD 3-Clause License
(see LICENSE for details).
Copyright Β© 2018-2025, A.A. Suvorov
All rights reserved.
--------------------------------------------------------