Skip to content

A simple, rclone-powered tool for easy configuration and seamless cross-cloud backup and synchronization.

Notifications You must be signed in to change notification settings

starriv/easy-rclone

Repository files navigation

Easy RClone v2.0

A modern, modular Python tool for cross-cloud storage backup and sync using rclone. This tool provides a clean, extensible architecture for managing backups across multiple cloud storage providers.

🚀 Features

  • Modular Architecture: Clean separation of concerns with dedicated modules
  • Multi-Cloud Support: Works with AWS S3, Alibaba Cloud OSS, Tencent COS, Cloudflare R2, and more
  • JSON Configuration: Simple, readable configuration format
  • Real-time Progress: Monitor backup progress with detailed statistics
  • Enhanced Connection Testing: Comprehensive diagnostics with bucket configuration verification
  • Smart Error Handling: Detailed troubleshooting suggestions for connection failures
  • Task Management: Organize backups into reusable tasks
  • CLI Interface: Professional command-line interface with comprehensive options
  • Zero Dependencies: Pure Python standard library implementation
  • Type Safety: Full type hints and validation
  • Error Handling: Comprehensive exception handling with custom error types

📦 Installation

From Source

git clone <repository-url>
cd easy-rclone
pip install -e .

Development Installation

pip install -e ".[dev]"

Requirements

🎯 Quick Start

1. Check rclone Installation

easy-rclone check-rclone

2. Create Configuration File

easy-rclone create-config

3. Edit Configuration

Edit cloud_config.json with your cloud storage credentials:

{
  "cloud_storages": [
    {
      "name": "tencent-cos",
      "type": "s3",
      "provider": "tencent",
      "access_key_id": "your-secret-id",
      "secret_access_key": "your-secret-key",
      "region": "ap-shanghai",
      "endpoint": "https://cos.ap-shanghai.myqcloud.com",
      "bucket": "your-bucket"
    },
    {
      "name": "cloudflare-r2",
      "type": "s3",
      "provider": "cloudflare",
      "access_key_id": "your-access-key-id",
      "secret_access_key": "your-secret-access-key",
      "region": "auto",
      "endpoint": "https://your-account-id.r2.cloudflarestorage.com",
      "bucket": "your-bucket"
    }
  ],
  "backup_tasks": [
    {
      "name": "cos-to-r2",
      "source": "tencent-cos:your-bucket/files/",
      "destination": "cloudflare-r2:your-bucket/backup/",
      "options": {
        "sync": "true",
        "transfers": "4",
        "bwlimit": "10M"
      }
    }
  ]
}

4. Test Configuration

# Test all backup tasks
easy-rclone test-all

# Test specific storage connection with detailed diagnostics
easy-rclone test-connection tencent-cos
easy-rclone test-connection cloudflare-r2

5. Enhanced Connection Testing

The test-connection command provides comprehensive diagnostics:

$ easy-rclone test-connection demo-cos
=== 测试存储连接: demo-cos ===
存储类型: s3
提供商: tencent
区域: ap-guangzhou
端点: https://cos.ap-guangzhou.myqcloud.com
存储桶: example-bucket-1234567890

测试连接路径: demo-cos:example-bucket-1234567890/
正在连接...
✓ 连接成功 - 找到 3 个文件/目录,大小: Total objects: 5

=== 详细信息 ===
文件数量: 3
路径大小: Total objects: 5
RClone版本: rclone v1.71.1

文件列表:
  backup/
  docs/
  images/

=== Bucket配置检查 ===
✓ 存储桶配置正确 - 可以成功访问
✓ Bucket级别访问正常 - 找到 3 个项目

5. Run Backup

easy-rclone run-task cos-to-r2

📋 Available Commands

Core Commands

  • easy-rclone check-rclone - Check if rclone is installed
  • easy-rclone create-config - Create sample configuration file
  • easy-rclone list-storages - List all configured cloud storages
  • easy-rclone list-tasks - List all configured backup tasks

Task Management

  • easy-rclone run-task <task-name> - Run specific backup task
  • easy-rclone test-task <task-name> - Test specific backup task
  • easy-rclone run-all - Run all backup tasks
  • easy-rclone test-all - Test all backup tasks

Connection Testing

  • easy-rclone test-connection <storage-name> - Test specific storage connection with detailed diagnostics
    • Shows storage configuration details
    • Displays connection status and file statistics
    • Verifies bucket configuration correctness
    • Provides troubleshooting suggestions for connection failures

Options

  • --config, -c <file> - Configuration file path (default: cloud_config.json)
  • --log-level <level> - Log level: DEBUG, INFO, WARNING, ERROR (default: INFO)
  • --no-progress - Disable progress display

🏗️ Architecture

Module Structure

rclone_backup/
├── __init__.py              # Package initialization
├── config/                  # Configuration management
│   ├── __init__.py
│   ├── manager.py          # ConfigManager class
│   └── models.py           # Data models (CloudStorage, BackupTask)
├── core/                    # Core functionality
│   ├── __init__.py
│   ├── backup.py           # BackupManager class
│   ├── storage.py          # StorageManager class
│   └── rclone.py           # RCloneExecutor class
├── utils/                   # Utility modules
│   ├── __init__.py
│   ├── logger.py           # Logging utilities
│   └── exceptions.py       # Custom exceptions
└── cli/                     # Command line interface
    ├── __init__.py
    └── main.py             # CLI entry point

Key Components

ConfigManager

  • Handles JSON configuration loading and validation
  • Provides configuration models with type safety
  • Manages configuration file creation and updates

StorageManager

  • Manages cloud storage configurations
  • Generates rclone configuration files
  • Handles storage-specific provider mappings

BackupManager

  • Manages backup tasks and execution
  • Provides task validation and testing
  • Handles backup strategies (sync vs copy)

RCloneExecutor

  • Wraps rclone command execution
  • Provides real-time progress monitoring
  • Handles error processing and reporting

🔧 Configuration Reference

Cloud Storage Types

  • s3: AWS S3, Alibaba Cloud OSS, Tencent COS, Cloudflare R2, etc.
  • oss: Alibaba Cloud OSS (legacy)

Provider Mappings

The tool automatically maps provider names to rclone-compatible values:

  • tencentTencentCOS
  • cloudflareCloudflare
  • aliyunAlibaba
  • huaweiHuaweiOBS
  • awsAWS

Backup Options

  • sync: Use sync mode instead of copy (true/false)
  • delete-mode: Delete files in destination that don't exist in source (true/false)
  • transfers: Number of parallel transfers (1-64)
  • checkers: Number of parallel checkers (1-64)
  • bwlimit: Bandwidth limit (e.g., "10M" for 10MB/s)

🐍 Python API Usage

from rclone_backup import ConfigManager, StorageManager, BackupManager, RCloneExecutor

# Initialize components
config_manager = ConfigManager("cloud_config.json")
config = config_manager.load_config()

rclone_executor = RCloneExecutor()
storage_manager = StorageManager()
storage_manager.load_from_config(config_manager)

backup_manager = BackupManager(rclone_executor, storage_manager)
backup_manager.load_from_config(config_manager)

# Create rclone config
storage_manager.create_rclone_config()

# Run backup task
success, message = backup_manager.run_task("cos-to-r2")
print(f"Backup result: {message}")

# Test connection
success, files = rclone_executor.list_remote("tencent-cos:your-bucket/")
if success:
    print(f"Found {len(files)} files")

🧪 Testing

Run the test suite:

# Run all tests
python -m pytest

# Run with coverage
python -m pytest --cov=rclone_backup

# Run specific test module
python -m pytest tests/test_config.py

📊 Development

Project Setup

# Clone repository
git clone <repository-url>
cd easy-rclone

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/macOS
# or
venv\Scripts\activate  # Windows

# Install development dependencies
pip install -e ".[dev]"

Code Quality

# Format code
black rclone_backup/

# Lint code
flake8 rclone_backup/

# Type checking
mypy rclone_backup/

🐛 Troubleshooting

Common Issues

  1. rclone not found

    easy-rclone check-rclone
    # Install rclone from https://rclone.org/downloads/
  2. Configuration errors

    easy-rclone test-all
    # Check configuration syntax and values
  3. Connection failures

    easy-rclone test-connection <storage-name>
    # Verify credentials and network connectivity
  4. Permission denied

    • Check API keys have correct permissions
    • Verify bucket access policies
    • Ensure network connectivity to cloud providers

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes and add tests
  4. Run the test suite: python -m pytest
  5. Commit your changes: git commit -am 'Add new feature'
  6. Push to the branch: git push origin feature-name
  7. Submit a pull request

📄 License

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

🙏 Acknowledgments

  • rclone - The amazing command-line program that powers this tool
  • All cloud storage providers for their excellent APIs and services
  • The Python community for the fantastic standard library

Happy backing up! 🚀

About

A simple, rclone-powered tool for easy configuration and seamless cross-cloud backup and synchronization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages