Skip to content

Professional modular solution for automatic cloning and backup of GitHub repositories and gists with step-by-step execution pipeline

License

Notifications You must be signed in to change notification settings

smartlegion/github-repos-backup-tools

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

122 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GitHub Repositories Backup Tools v1.1.0

GitHub release (latest by date) GitHub top language GitHub Python Version Platform GitHub last commit GitHub Stars

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


⚠️ IMPORTANT NOTE: If you experience any issues with v1.1.0, please report them in the Issues section and temporarily use the latest stable version v0.9.4 while we investigate.


πŸš€ Key Features

  • Complete Backup - Clone both public and private repositories/gists
  • Smart Update System - Only updates repositories with recent changes (5-minute threshold)
  • Resilient Retry Mechanism - Automatic retries for failed operations
  • Archive Support - Create timestamped compressed ZIP archives in home directory
  • System Control - Option to shutdown/reboot after completion (mutually exclusive)
  • Real-time Monitoring - Progress tracking with detailed statistics
  • Cross-platform - Works on Windows, Linux, macOS and Termux (Android)
  • Configurable Timeout - Set custom timeout for Git operations (--timeout N)
  • Security - Path traversal attack protection and secure token storage
  • Detailed Reporting - Comprehensive success/failure reports
  • Instant Process Termination - Single Ctrl+C stops all operations immediately
  • Git Repository Health Checks - Prevents broken clones with integrity validation
  • Git Health Verification - Automatic detection and repair of broken repositories
  • Verbose Numbering - Clear progress tracking with item counters in debug mode

πŸ–₯ System Requirements

  • Python: 3.8+
  • Git: 2.20+
  • SSH client (for authentication)
  • Storage: 100MB+ free space (varies by repository size)
  • Network: Stable internet connection

πŸš€ Quick Start

1. Installation

git clone https://github.com/smartlegionlab/github-repos-backup-tools.git
cd github-repos-backup-tools

2. First Run (Automatic Token Setup)

python app.py -r -g

The application will guide you through token setup on first run.

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

Basic Commands

Command Description
-r Backup repositories
-g Backup gists
-t Update token
--archive Create compressed backup archive
--verbose Detailed debug output
--timeout N Git operation timeout (seconds)

Power Management

Command Description
--shutdown Shutdown after completion
--reboot Restart after completion

Note: --shutdown and --reboot are mutually exclusive.

Common Usage Examples

# Basic repository backup
python app.py -r

# Complete backup (repos + gists)
python app.py -r -g

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

# Backup with system shutdown
python app.py -r -g --shutdown

# Backup with system reboot
python app.py -r -g --reboot

# Debug mode with custom timeout
python app.py -r --verbose --timeout 60

# Update token
python app.py -t

πŸ“‚ Backup Structure

~/
β”œβ”€β”€ [username]_github_backup/          # Main backup directory
β”‚   β”œβ”€β”€ repositories/                  # All cloned repositories
β”‚   └── gists/                         # All cloned gists
└── github_[username]_YYYY-MM-DD_HH_MM_SS.zip  # Auto-generated archive

Smart Update System

  • Compares local commit dates with GitHub pushed_at timestamps
  • 5-minute threshold to avoid unnecessary git pull operations
  • Maintains data integrity while improving performance

Security Features

  • Secure token storage in user config directory
  • Path traversal protection
  • Input validation and sanitization
  • Graceful error handling

πŸ“Š Performance Optimizations

  • Selective Updates: Only updates repositories with changes >5 minutes old
  • Immediate Retries: Failed operations automatically retried without delay
  • Progress Tracking: Real-time feedback without verbose overhead
  • Memory Efficient: Streamlined processing for large repository sets

πŸ›  Troubleshooting

Common Issues

Q: Authentication fails?
A: Verify token has repo and gist permissions and SSH key is properly set up. Use --verbose for details.

Q: Clone operations timeout?
A: Increase timeout: --timeout 60 for slower connections.

Q: Where is my token stored?
A: In OS-specific config directory: ~/.config/github_repos_backup_tools/

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

Q: SSH connection fails?
A: Verify SSH key is added to GitHub and test with ssh -T git@github.com


⚠️ IMPORTANT NOTE: If you experience any issues with v1.1.0, please report them in the Issues section and temporarily use the latest stable version v0.9.4 while we investigate.


Author: Alexander Suvorov
License: BSD 3-Clause License
Support: GitHub Issues
Source: https://github.com/smartlegionlab/

πŸ”’ Security Notice

This application:

  • Stores tokens in user-specific config directories
  • Validates all file paths to prevent directory traversal attacks
  • Uses minimal required permissions (repo, gist)
  • Does not transmit data to third parties
  • Provides clear audit trails of all operations

πŸ“„ License

Licensed under the terms of the BSD 3-Clause License
Copyright Β© 2025, Alexander Suvorov
All rights reserved.

⚠️ Disclaimer

THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. Use at your own risk. The authors are not responsible for data loss, system instability, or any other issues arising from software use. Always test with non-critical data first.

Legal Compliance: Users are responsible for ensuring their use of this software complies with:

  • GitHub's Terms of Service and API guidelines
  • Local laws and regulations regarding data backup and access
  • Copyright and intellectual property rights
  • Any applicable export control laws

Rate Limiting: This tool uses GitHub's API - respect rate limits and avoid excessive requests that may impact GitHub's services.

Data Responsibility: You are solely responsible for the data you backup, including its security, storage, and legal compliance.


πŸ“Œ Development Status: This application is currently in active development. While we strive for stability, some features may not work as expected. We appreciate your feedback and bug reports to help improve the software.


⭐ Star this repo if you find it useful!


OUTPUT

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


πŸ”§ Arguments Parsing: 
Parsing command line arguments...

πŸ“‹ Parsed arguments:
   Backup: πŸ“¦ Repositories, πŸ“ Gists, πŸ—„ Archive
   Timeout: 30s
   Verbose: ❌ Disabled
   Power: ❌ No action

βš™οΈ Configuration Setup: 
Checking and setting up configuration directories

πŸ“ Configuration directory: /home/user_name/.config/github_repos_backup_tools/github_token.json

πŸ”‘ Getting GitHub token: 

βœ… Token obtained successfully

πŸ”‘ GitHub Authentication: 
Authenticating with GitHub...
   πŸ”„ Attempt 1/3 (timeout: 30s)... βœ… (0.5s)
βœ… Authenticated as: user_name

πŸ“ Directory Setup: 
Creating backup directory structure...
πŸ“ Main backup directory: /home/user_name/user_name_github_backup
   βœ… repositories/
   βœ… gists/

πŸ”„ Repositories Operations: 
Fetching and cloning/updating repositories...
   πŸ”„ Attempt 1/3 (timeout: 30s)... βœ… (2.0s)
   πŸ”„ Attempt 1/3 (timeout: 30s)... βœ… (2.1s)
   πŸ”„ Attempt 1/3 (timeout: 30s)... βœ… (2.1s)
   πŸ”„ Attempt 1/3 (timeout: 30s)... βœ… (0.5s)
βœ… Found 100 repositories

πŸ“¦ Processing 100 repositories...
[##########] 100.00% | 100/100 | Failed: 0 | Processing: user_name/repo_name_...
βœ… Cloning/updating repositories completed successfully!


πŸ”„ Gists Operations: 
Fetching and cloning/updating gists...
   πŸ”„ Attempt 1/3 (timeout: 30s)... βœ… (0.5s)
   πŸ”„ Attempt 1/3 (timeout: 30s)... βœ… (0.4s)
βœ… Found 1 gists

πŸ“ Processing 1 gists...
[##########] 100.00% | 1/1 | Failed: 0 | Processing: a2e7733c3ba32963b7c0985e...
βœ… Cloning/updating gists completed successfully!


βœ… Verification: 
Verifying that all repositories and gists are properly cloned/updated...
πŸ“Š Repositories verification:
   Total: 100
   Valid: 100
   Missing: 0
πŸ“Š Gists verification:
   Total: 1
   Valid: 1
   Missing: 0
βœ… All items verified successfully!

πŸ“Š Report: 
Generating backup report...

πŸ“¦ REPOSITORIES:
   Total: 100
   βœ… Successful: 100
   ❌ Failed: 0
   πŸŽ‰ All repositories processed successfully!

πŸ“ GISTS:
   Total: 1
   βœ… Successful: 1
   ❌ Failed: 0
   πŸŽ‰ All gists processed successfully!

πŸ’Ύ BACKUP LOCATION:
   /home/user_name/user_name_github_backup

πŸŽ‰ SUCCESS: All backup operations completed successfully!
============================================================

πŸ—„οΈ Archive Creation: 
Creating backup archive...
βœ… Archive created successfully: /home/user_name/github_user_name_2025-11-19_18_11_46.zip
--------------------------------------------------------------------------------
---------------------- https://github.com/smartlegionlab/ ----------------------
--------------------- Copyright Β© 2025, Alexander Suvorov ----------------------
********************************************************************************

About

Professional modular solution for automatic cloning and backup of GitHub repositories and gists with step-by-step execution pipeline

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%