HostImageBackup

A modular Python CLI tool for backing up images from various image hosting services to your local machine with ease.

A modular Python CLI tool for backing up images from various image hosting services to your local machine with ease.

πŸš€ Features

  • πŸ—οΈ Modular Architecture - Easy to extend with new providers
  • 🌐 Multi-Provider Support - Aliyun OSS, Tencent COS, SM.MS, Imgur, GitHub
  • πŸ“Š Visual Progress - Beautiful progress bars for backup operations
  • 🎨 Rich CLI Interface - Intuitive command-line experience
  • βš™οΈ Flexible Configuration - YAML-based configuration management
  • πŸ”„ Resume Support - Continue interrupted transfers seamlessly
  • πŸ“ Comprehensive Logging - Detailed operation logs
  • πŸ§ͺ Well Tested - Comprehensive test coverage for reliability

🎯 Why This Tool?

In today’s digital world, we store images across multiple cloud services and platforms. This tool solves the challenge of:

  • Backing up and migrating images from cloud providers to local storage
  • Multi-provider aggregation - consolidating images from multiple services
  • Scheduled backups via cron jobs or CI/CD pipelines
  • Archive management - creating organized local image archives
  • Disaster recovery - maintaining offline copies for business continuity

πŸ“‹ Supported Providers

Provider Features Notes
OSS βœ… List, backup, resume, skip Requires Aliyun credentials
COS βœ… List, backup, resume, skip Requires Tencent credentials
SM.MS βœ… List, backup Public API, rate limits apply
Imgur βœ… List, backup Requires Imgur client ID/secret
GitHub βœ… List, backup Requires GitHub token & access

πŸ› οΈ Installation

Prerequisites

  • Python 3.10+
  • Network connectivity for backup operations
# Install from PyPI
pip install host-image-backup

# Verify installation
host-image-backup --help
# Or use the short alias
hib --help

Method 2: Development Install

# Clone the repository
git clone https://github.com/WayneXuCN/HostImageBackup.git
cd HostImageBackup

# Install with uv (recommended)
uv lock
uv sync --all-extras

# Or use pip
pip install -e ".[dev]"

πŸš€ Quick Start

Basic Usage

# 1. Initialize configuration
host-image-backup init

# 2. Edit the configuration file
# Linux/macOS: ~/.config/host-image-backup/config.yaml
# Windows: %APPDATA%/host-image-backup/config.yaml

# 3. Test provider connection
host-image-backup test oss

# 4. Backup images from a provider
host-image-backup backup oss --output ./my-backup

# 5. Backup from all enabled providers
host-image-backup backup-all --output ./full-backup

Configuration Example

# Global settings
default_output_dir: "./backup"
max_concurrent_downloads: 5
timeout: 30
retry_count: 3
log_level: "INFO"

# Provider configurations
providers:
  oss:
    enabled: true
    access_key_id: "your_access_key"
    access_key_secret: "your_secret_key"
    bucket: "your_bucket_name"
    endpoint: "oss-cn-hangzhou.aliyuncs.com"
    prefix: "images/"

  github:
    enabled: true
    token: "ghp_your_personal_access_token"
    owner: "your_username"
    repo: "your_repository"
    path: "images"

πŸ“ Project Structure

HostImageBackup/
β”œβ”€β”€ src/host_image_backup/     # Main package
β”‚   β”œβ”€β”€ providers/             # Provider implementations
β”‚   β”œβ”€β”€ config.py             # Configuration management
β”‚   β”œβ”€β”€ cli.py                # Command-line interface
β”‚   └── services.py           # Core backup services
β”œβ”€β”€ tests/                    # Test suite
β”œβ”€β”€ pyproject.toml           # Project metadata and dependencies
└── README.md               # Documentation

πŸ”§ How It Works

  1. Configuration Loading - Reads provider settings from YAML config
  2. Provider Discovery - Automatically detects enabled providers
  3. Image Listing - Fetches available images from each provider
  4. Concurrent Download - Downloads images with progress tracking
  5. Error Handling - Retries failed downloads and logs errors
  6. Resume Support - Skips existing files for interrupted transfers

πŸ“– Advanced Usage

CLI Command Reference

Command Description Aliases
init Initialize default configuration file -
backup Backup images from specific provider -
backup-all Backup from all enabled providers -
list List all available providers list-providers
test Test provider connection -
info Show detailed provider information -

Use Cases

  • Personal Photo Backup: Backup all your photos from multiple services
  • Migration Between Providers: Export from one service and import to another
  • Scheduled Backups: Automate backups with cron jobs
  • Archive Management: Create organized local image collections

πŸ” Key Features in Detail

The tool provides enterprise-grade features:

  • βœ… Asynchronous operations for faster backup speeds
  • βœ… Intelligent retry logic for network failures
  • βœ… Comprehensive logging for audit trails
  • βœ… Modular design for easy extension
  • βœ… Type-safe configuration with Pydantic validation
  • βœ… Rich console output with progress indicators

πŸ›‘οΈ Security & Best Practices

  • Credential Security: Never commit credentials to version control
  • Environment Variables: Support for environment-based configuration
  • File Permissions: Automatic secure configuration file permissions
  • Network Security: HTTPS-only connections and timeout handling

πŸ™ Acknowledgments

This project leverages modern Python tools and best practices:

  • Typer: For beautiful CLI interfaces
  • Rich: For enhanced console output
  • Pydantic: For robust configuration validation
  • Loguru: For comprehensive logging

🀝 Contributing

Contributions are welcome! The project follows modern Python development practices:

  • Type hints throughout the codebase
  • Comprehensive test coverage with pytest
  • Code formatting with Ruff
  • Pre-commit hooks for code quality
  • CI/CD with GitHub Actions

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

This page was automatically translated by generative AI and may contain inaccuracies or incomplete information. Feedback is welcome to help us improve.