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/mongorestoreand 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
- Secure connection manager backed by the OS keychain/keyring
- Dynamic environment configuration for legacy, CI, and one-off use
- Saved sync plans with hash-bound approvals
- Operation audit records and backup-based revert support
- OS-backed human approval gate for protected/production targets
- Create, verify, 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 (
mongodumpandmongorestoreexecutables) - Rust and Cargo (install from https://rustup.rs)
Build from source
# Clone the repository
# Build the project
# The binary will be available at target/release/arcula
Running with cargo
# Run directly with cargo
Configuration
Recommended: secure connection manager
Store connection names and safety metadata in Arcula, while the raw MongoDB URI is stored in your OS secure storage:
- macOS: Keychain
- Windows: Credential Manager
- Linux: kernel keyring
# Prompts securely for the URI, then stores it in the OS keychain/keyring
# Or pipe/pass a URI for automation. Prefer --uri-stdin over --uri to avoid shell history.
|
List and inspect configured connections without exposing raw credentials:
Sync can then use the stored names:
Stored connection metadata lives at your platform config path (or ARCULA_CONFIG_DIR) in connections.json; the URI itself is not written there. Plans, approvals, operations, and local audit metadata live under your platform data path (or ARCULA_DATA_DIR). The metadata format includes:
Production/protected targets cannot be dropped or cleared unless --backup true is enabled and the backup succeeds. They also require the saved plan + OS-backed approval flow before execution.
Adjust per-connection policy flags when needed:
Protected/prod connections always keep a safety floor: agent apply is disabled, human approval is required, destructive backup is required, and backup verification is required.
Legacy / CI: .env and direct URIs
.env is still supported for CI, Docker, and one-off use:
# 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
# Optional environment metadata for safety and agent use
# Values: local, dev, staging, prod, other
MONGO_LOCAL_KIND=local
MONGO_DEV_KIND=dev
MONGO_STG_KIND=staging
MONGO_PROD_KIND=prod
# Optional extra protection for non-prod targets
# MONGO_STG_PROTECTED=true
# 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
Import existing .env entries into secure storage:
Arcula dynamically detects all stored connections plus .env variables following MONGO_<ENV>_URI. It also reads optional metadata from MONGO_<ENV>_KIND (or _TYPE / _ROLE). If omitted, LOCAL, DEV, STG, and PROD are inferred from the name.
Usage
Display information about available environments
This command will show all configured MongoDB environments and their databases.
Safer plan / approve / operation flow
For protected/production targets, and whenever you want an auditable workflow, use:
# 1. Create a saved sync plan. No database changes happen here.
# 2. Review as text or Markdown.
# 3. Approve. Protected plans require an interactive terminal and OS user presence
# via macOS/Linux sudo, with Linux polkit/pkexec attempted first when available.
# 4. Execute and save operation/audit metadata.
# 5. Revert from the backup created before the operation, if needed.
Agents can create plans and run safe/dev plans when the target connection policy allows allow_agent_apply=true:
For protected/prod targets, agent execution returns a human-approval-required error until a human runs arcula plan approve <plan-id> from an interactive terminal. Passwordless sudo is rejected as an approval provider because it does not prove user presence.
Immediate synchronization
Interactive mode (will prompt for missing options):
With command-line options:
Options:
--from: Source stored connection or.envenvironment--to: Target stored connection or.envenvironment--from-uri: Source MongoDB URI; bypasses.envfor source--to-uri: Target MongoDB URI; bypasses.envfor target--from-kind/--to-kind: Environment kind override (local,dev,staging,prod,other)--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--agent: JSON output, no colors/progress, no prompts--dry-run: Output the sync plan without executingsync plan: Save a hash-bound plan for later approval/executionplan approve: Save an approval record; protected plans require OS user presenceoperation run: Execute a saved plan and record operation metadataoperation revert: Restore the target DB from the operation's pre-sync backup--format json: Machine-readable output forinfoand sync plans/results--no-env: Do not load.env
Examples
# Synchronize 'users' database from DEV to LOCAL environment with interactive prompts
# Synchronize 'products' database from PROD to STG environment without prompts
# Synchronize 'analytics' database from RANDOM to DEV environment with custom target db
# Agent-friendly dry run using direct URIs, without reading .env
# Agent-friendly saved plan flow for a policy-allowed dev target
# Protected/prod target flow with human approval
# JSON environment/connection discovery
# Manage secure stored connections
Contributing
Contributions are welcome! Feel free to submit a pull request with your changes.
License
MIT