MusicBrainz Light
A high-performance Rust implementation for creating and maintaining MusicBrainz database mirrors with automatic schema updates.
This project is a modernized clone of mbslave that provides significant performance improvements and automatic schema update capabilities, eliminating the need for manual schema migrations.
Features
- 🚀 High Performance: Written in Rust with async/await for optimal performance
- 🔄 Automatic Schema Updates: Handles schema changes automatically without manual intervention
- 📦 Easy Setup: Simple configuration and Docker support
- 🎯 Selective Sync: Configure which schemas and tables to replicate
- 📊 Progress Tracking: Built-in progress bars for long-running operations
- 🔧 Flexible Configuration: Support for TOML files and environment variables
- 🐳 Docker Ready: Includes Docker Compose setup for easy deployment
Improvements over mbslave
- Automatic Schema Updates: No more manual schema upgrade scripts
- Better Performance: Rust implementation with optimized database operations
- Modern Tooling: Built with modern async Rust ecosystem
- Simplified Maintenance: Reduced operational overhead
- Enhanced Error Handling: Better error messages and recovery
Installation
From Source
The binary will be available at target/release/mbpg-light.
Using cargo
Configuration
Configuration File
Create a config.toml file in your project directory or /etc/mblight/config.toml:
[]
= "musicbrainz"
= "musicbrainz"
= "localhost"
= 5432
= "musicbrainz"
[]
= "https://data.musicbrainz.org"
= "your-musicbrainz-token"
[]
# Optional: specify which tables to keep (empty = keep all)
= []
[]
# Optional: specify which schemas to keep (empty = keep all)
= []
Getting a MusicBrainz Token
- Visit MetaBrainz website
- Create an account or log in
- Generate an API token for database replication
Usage
Initialize Database
To create a new MusicBrainz mirror from scratch:
This command will:
- Download the latest MusicBrainz SQL dump
- Create database schemas
- Import all data
- Set up replication control
- Apply indexes and constraints
Sync Database
To keep your database up-to-date with incremental changes:
# Sync once and exit when caught up
# Sync continuously, waiting for new replication packets
This command will:
- Download and apply replication packets
- Automatically handle schema updates
- Process pending data changes
- Continue until all updates are applied (or loop infinitely with
--loop)
Logging
Configure logging levels using the RUST_LOG environment variable:
# Info level (default)
# Debug level
Selective Replication
You can configure which schemas and tables to replicate by modifying your config.toml:
[]
= ["musicbrainz", "cover_art_archive"]
[]
= ["artist", "release", "recording", "work"]
This is useful for:
- Reducing database size
- Focusing on specific data subsets
- Testing with smaller datasets
Using as a library
You can use musicbrainz-light as a library in your Rust projects for programmatic access to MusicBrainz database operations.
Add Dependency
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["rt-multi-thread"] }
= { = "0.8", = ["postgres", "runtime-tokio"] }
Feature Flags
The library supports several optional features:
progress(default): Enables progress bars during operationscli: Command-line interface dependencies (not needed for library usage)
# Minimal library usage without CLI dependencies
[]
= { = "0.1", = false }
# With progress bars
[]
= { = "0.1", = false, = ["progress"] }
Basic Usage
use ;
async
Configuration Options
Using Default Settings
The default Settings struct loads configuration from:
- Environment variables with
METADADA__prefix /etc/mblight/config.tomlconfig.tomlin current directory
use Settings;
let settings = get?;
Custom Settings Implementation
You can implement your own configuration by implementing the MbLightSettingsExt trait:
use MbLightSettingsExt;
// Use with MbLight
let custom_config = MyCustomSettings ;
let mb_light = try_new.await?;
With Notifications
When building MbLight with a mpsc::Sender , you can receive notifications when replication reaches the latest packet:
use mpsc;
async
Utility Methods
Check if a table has data:
let has_artists = mb_light.has_data.await?;
if has_artists
Development
Prerequisites
- Rust 1.75+ (2024 edition)
- PostgreSQL 12+
- Git
Building
# Debug build
# Release build
# Run tests
# Check formatting and linting
Features
The project supports several feature flags:
cli(default): Command-line interface with colored outputprogress(default): Progress bars for long operations
# Build without CLI features
# Build with specific features
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Acknowledgments
- Original mbslave project by Lukáš Lalinský
- MusicBrainz for providing the database and replication infrastructure
- The Rust community for excellent async and database libraries
Support
- Open an issue for bug reports or feature requests
- Check existing issues before creating new ones
- Provide detailed information including configuration and logs
Changelog
See CHANGELOG.md for version history and changes.