2 stable releases
new 1.0.5 | May 19, 2025 |
---|---|
1.0.4 | May 17, 2025 |
#307 in Database interfaces
379 downloads per month
41KB
823 lines
Arcula - MongoDB Database Synchronization Tool
From author: This project exists to help me with my development workflow. I often need to synchronize MongoDB databases between different environments (local, dev, staging, not production 🙈). Before, I used raw
mongodump
/mongorestore
and relied on atuin ✨ (great tool btw) to switch between. This tool is a simple wrapper around these commands and with help of AI (Claude Code) it took max 2 hours to implement. Somehow for me it is much more convenient to use and maybe it will be useful for someone else too. 🙌
Arcula is a CLI application for synchronizing MongoDB databases between different environments. It allows you to easily export databases from one MongoDB instance and import them to another.
Features
- Export databases from one MongoDB instance
- Import databases to another MongoDB instance
- Dynamic environment configuration (not limited to predefined environments)
- Create and restore backups
- Interactive mode with prompts for missing options
- Progress indicators for long-running operations
- Colored terminal output
- Automatic detection of MongoDB tools
Installation
Prerequisites
- MongoDB Tools (
mongodump
andmongorestore
executables) - Rust and Cargo (install from https://rustup.rs)
Build from source
# Clone the repository
git clone https://github.com/ggagosh/arcula.git
cd arcula
# Build the project
cargo build --release
# The binary will be available at target/release/arcula
Running with cargo
# Run directly with cargo
cargo run -- [COMMAND] [OPTIONS]
Configuration
Create a .env
file in the root directory of the project with the following variables:
# MongoDB Connection URIs - You can add any environment you need
MONGO_LOCAL_URI=mongodb://localhost:27017
MONGO_DEV_URI=mongodb://user:password@dev.example.com:27017
MONGO_STG_URI=mongodb://user:password@stg.example.com:27017
MONGO_PROD_URI=mongodb://user:password@prod.example.com:27017
MONGO_RANDOM_URI=mongodb://user:password@random.example.com:27017
# Path to MongoDB binaries (optional, auto-detected if not specified)
MONGODB_BIN_PATH=/usr/local/bin
# Backup directory
BACKUP_DIR=./backups
# Logging level: trace, debug, info, warn, error
RUST_LOG=info
You can copy the sample.env
file and modify it for your needs. The application will dynamically detect all MongoDB environments from environment variables following the pattern MONGO_<ENV>_URI
.
Usage
Display information about available environments
cargo run -- info
This command will show all configured MongoDB environments and their databases.
Synchronize databases between environments
Interactive mode (will prompt for missing options):
cargo run -- sync
With command-line options:
cargo run -- sync --from LOCAL --to DEV --db my_database --backup true
Options:
--from
: Source environment (any configured environment)--to
: Target environment (any configured environment)--db
: Database to synchronize--target-db
: Target database name (defaults to source database name)--backup
: Whether to create a backup before import (true/false, defaults to true)--drop
: Whether to drop collections during import (true/false, defaults to true)--clear
: Whether to clear collections during import (true/false, defaults to false, ignored if drop is enabled)--interactive
: Enable interactive prompts
Examples
# Synchronize 'users' database from DEV to LOCAL environment with interactive prompts
cargo run -- sync --from DEV --to LOCAL --db users --interactive
# Synchronize 'products' database from PROD to STG environment without prompts
cargo run -- sync --from PROD --to STG --db products
# Synchronize 'analytics' database from RANDOM to DEV environment with custom target db
cargo run -- sync --from RANDOM --to DEV --db analytics --target-db analytics_copy
Contributing
Contributions are welcome! Feel free to submit a pull request with your changes.
License
MIT
Dependencies
~25–40MB
~651K SLoC