logo
0
0
WeChat Login

git-backup-tool

A Git repository backup tool written in Rust — batch clone, incremental pull, and package repositories into compressed archives.

Features

  • init — Initialize configuration directory (~/.config/git-backup/) and generate a sample repository list
  • clone — Batch clone repositories from a URL list with concurrent downloads and progress bars
  • pull — Incremental pull updates for all existing local repositories
  • backup — Full backup workflow: clone missing repos, pull updates, then pack archives
  • pack — Package repositories into .tar.gz archives with progress indication

Installation

From source

git clone https://github.com/your-username/git-backup-tool.git
cd git-backup-tool
cargo build --release
./target/release/git-backup-tool --help

Via CNB pipeline

The project includes a .cnb.yml CI/CD pipeline that builds and releases binaries on tag push.

Quick Start

# 1. Initialize configuration
git-backup-tool init

# 2. Edit the repository list (default: ~/.config/git-backup/repos.txt)
#    Add one Git URL per line, e.g.:
#    https://github.com/rust-lang/rust.git
#    https://github.com/tokio-rs/tokio.git

# 3. Clone all repositories
git-backup-tool clone

# 4. Pull latest changes
git-backup-tool pull

# 5. Package as tar.gz archives
git-backup-tool pack

# 6. Full backup (clone + pull + pack in one command)
git-backup-tool backup

Configuration

Configuration file: ~/.config/git-backup/config.toml

[general]
# Backup storage directory
backup_dir = "~/.config/git-backup/backups"

[git]
# Default clone depth (0 = full history)
depth = 1
# Number of concurrent git operations
concurrency = 4
# Number of retries on failure
retries = 3

[packaging]
# Compression level (1-9)
compression_level = 6
# Output directory for packages
output_dir = "~/.config/git-backup/backups/packages"

[advanced]
# Log level: trace, debug, info, warn, error
log_level = "info"

Architecture

git-backup-tool/
├── Cargo.toml
├── src/
│   ├── main.rs         # CLI entry (clap derive) — 5 subcommands
│   ├── config.rs       # TOML config parsing and management
│   ├── logger.rs       # Logging system (tracing)
│   ├── file_io.rs      # File I/O: repo list, backup records
│   ├── git_ops.rs      # Git operations with retry + concurrency
│   ├── backup.rs       # Backup workflow orchestration
│   └── packager.rs     # tar.gz packaging module
├── docs/
│   ├── ARCHITECTURE.md
│   ├── IMPLEMENTATION_PLAN.md
│   ├── TEST_PLAN.md
│   └── ...
├── scripts/
│   ├── start.sh        # Environment setup
│   ├── build.sh        # Build script
│   ├── test.sh         # Test runner
│   ├── release.sh      # Release workflow
│   └── dev.sh          # Development mode
└── .cnb.yml            # CI/CD pipeline configuration

Key design decisions

DecisionChoice
Git backendSystem git commands (not libgit2)
Async runtimetokio (rt-multi-thread + sync + time)
Concurrencytokio::sync::Semaphore-controlled
Retry strategyExponential backoff: 2s, 4s, 8s
Progress displayindicatif ProgressBar via Arc sharing
ConfigurationCustom TOML parser (no config crate)
Packagingflate2 + tar (output in packages/ subdirectory)

Dependencies

CrateVersionPurpose
clap4.5CLI framework (derive)
tokio1.0Async runtime (minimal features)
serde1.0Serialization/deserialization
toml0.8TOML configuration parser
tracing0.1Logging framework
tracing-subscriber0.3Log output formatting
flate21.0gzip compression
tar0.4Tarball creation
indicatif0.17Progress bars
chrono0.4Timestamps for records
dirs5.0System directory paths
anyhow1.0Error handling

Testing

  • 48 unit tests — pure function tests with tempfile isolation
  • ~85 total tests planned — covering all modules
cargo test

Release History

v0.1.0 (2026-05-08)

  • All 5 subcommands implemented (init, clone, pull, backup, pack)
  • Concurrent git operations with semaphore-based throttling
  • Exponential backoff retry (up to 3 attempts)
  • Progress bars for clone/pull/pack operations
  • 48 unit tests passing
  • TOML-based configuration management

License

MIT

About

为分布于不同平台的 git 仓库进行备份

Language
Rust79.3%
Shell20.7%