A Python-based command-line tool for backing up images from multiple image hosting services to local storage
Project description
Host Image Backup
Host Image Backup is a modular Python CLI tool for backing up images from various image hosting services to your local machine.
Features
- Modular architecture, easy to extend
- Supports Aliyun OSS, Tencent COS, SM.MS, Imgur, GitHub
- Progress bar for backup
- Rich command-line interface
- Flexible configuration management
- Resume interrupted transfers
- Detailed logging
Supported Providers
| Provider | Supported Features | Limitations / Notes |
|---|---|---|
| OSS | List, backup, resume, skip | Requires valid Aliyun credentials |
| COS | List, backup, resume, skip | Requires valid Tencent credentials |
| SM.MS | List, backup | Public API, rate limits may apply |
| Imgur | List, backup | Requires Imgur client ID/secret |
| GitHub | List, backup | Requires GitHub token, repo access |
Installation
Requirements
- Python 3.10+
- pip or uv
- (Recommended) virtual environment
Dependencies
- See pyproject.toml for all dependencies.
- Compatible with Linux, macOS, Windows.
Install from Source
pip install -e .
# or
uv pip install -e .
Install via PyPI
pip install host-image-backup
# Or upgrade to the latest version
pip install --upgrade host-image-backup
Configuration
The config file is located at ~/.config/host-image-backup/config.yaml.
Each provider section must be filled with valid credentials.
Configuration Fields
| Field | Description |
|---|---|
| access_key_id | Aliyun OSS access key |
| access_key_secret | Aliyun OSS secret key |
| bucket | Bucket name |
| endpoint | OSS endpoint |
| prefix | Path prefix for images |
| secret_id | Tencent COS secret ID |
| secret_key | Tencent COS secret key |
| region | COS region |
| client_id | Imgur client ID |
| client_secret | Imgur client secret |
| token | GitHub token |
| repo | GitHub repository name |
Example: Aliyun OSS
providers:
oss:
access_key_id: "your_access_key"
access_key_secret: "your_secret_key"
bucket: "your_bucket_name"
endpoint: "oss-cn-hangzhou.aliyuncs.com"
prefix: "images/"
Example: Tencent COS
providers:
cos:
secret_id: "your_secret_id"
secret_key: "your_secret_key"
bucket: "your_bucket_name"
region: "ap-guangzhou"
prefix: "images/"
CLI Usage
Command Overview
| Command | Description |
|---|---|
init |
Initialize config file |
backup |
Backup images from provider |
list-providers |
List available providers |
test |
Test provider connection |
Command Details
init
Initialize a default config file.
host-image-backup init
backup
Backup images from a provider.
host-image-backup backup --provider oss --output ./backup
Options:
--provider <name>: Specify provider (oss, cos, smms, imgur, github)--output <dir>: Output directory for backups--config <path>: Use custom config file--limit <n>: Limit number of images to download--skip-existing: Skip files already downloaded--verbose: Show detailed logs
list-providers
List all available providers.
host-image-backup list-providers
test
Test connection to a provider.
host-image-backup test --provider oss
Typical Use Cases
- Mirror images from cloud providers to local disk for backup or migration.
- Aggregate images from multiple providers into a unified local archive.
- Automate scheduled backups via cron or CI/CD.
Error Handling & FAQ
Common Issues
- Invalid credentials: Check your config file for typos.
- Network errors: Ensure internet connectivity.
- Rate limits: Some providers (SM.MS, Imgur) may restrict requests.
- Permission denied: Verify access rights for output directory.
Troubleshooting
- Run with
--verbosefor detailed logs. - Check log files in the output directory.
- For provider-specific issues, consult their official docs.
Security Notes
- Credential Protection: Never share your config file or credentials publicly.
- Use environment variables or secret managers for sensitive data if possible.
- Restrict file permissions for config files (
chmod 600 ~/.config/host-image-backup/config.yaml).
Extending & Custom Providers
- To add a new provider, implement a subclass in
src/host_image_backup/providers/. - See src/host_image_backup/providers/base.py for the provider interface.
- Contributions for new providers are welcome!
Project Roadmap
- Add more image hosting providers
- Web UI for configuration and monitoring
- Scheduled backup support
- Enhanced error reporting
- Multi-threaded download
Development
Environment Setup
git clone git@github.com:WayneXuCN/HostImageBackup.git
cd HostImageBackup
python -m venv .venv
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
pip install -e ".[dev]"
pre-commit install
Testing
pytest
Formatting
black src tests
Type Checking
mypy src
Contributing
- Fork the repo
- Create your feature branch (
git checkout -b feature/foo) - Commit your changes (
git commit -am 'Add foo feature') - Push to the branch (
git push origin feature/foo) - Open a Pull Request
Please read CONTRIBUTING.md for details.
Community & Support
- GitHub Issues: Submit here
- Discussions: GitHub Discussions
- Email: wayne.xu.cn@gmail.com
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file host_image_backup-0.1.0a1.tar.gz.
File metadata
- Download URL: host_image_backup-0.1.0a1.tar.gz
- Upload date:
- Size: 80.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6b56b805749c3485628d65fb98fa42922675de3f66f783880e24c5358b102c5
|
|
| MD5 |
d0bafdc6e33433c3ab715f1435989b6e
|
|
| BLAKE2b-256 |
05192ee2a661343478708c6e656ea0df9367cc082089477784c9fe216b367369
|
File details
Details for the file host_image_backup-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: host_image_backup-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01ec2fa89a562a3f12d322f62c114ef04f1b22a018504cf276cad411f23030ae
|
|
| MD5 |
f62749a488c999e6d3985e1f273ff908
|
|
| BLAKE2b-256 |
d8e2a6d28f4b0e02384861eedacc7f127b8332badded82685bc984370d77414a
|