Compare commits
13 Commits
dbutils_mongo
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 148ad340d6 | |||
| 5817347d6e | |||
| 6a87248cc0 | |||
| c81abeda54 | |||
| 52f28d517b | |||
| d20c14c179 | |||
| ff6c2205d1 | |||
| 8949a33481 | |||
| f804b7abad | |||
| 743f7d71c1 | |||
| 3b2cfcd622 | |||
| dfd8f7b22b | |||
| b5c1ac95b7 |
@@ -0,0 +1,64 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
A collection of standalone Bash utility scripts for MongoDB operations (backup, restore, local dev environment). No build system, package manager, or test suite — each module is a self-contained shell script.
|
||||||
|
|
||||||
|
## Modules
|
||||||
|
|
||||||
|
| Module | Script | Purpose |
|
||||||
|
|---|---|---|
|
||||||
|
| `dbdump_mongo/` | `db-dump.sh` | Dump MongoDB databases across multiple named environments |
|
||||||
|
| `dbrestore_mongo/` | `db-restore.sh` | Restore a MongoDB dump to a target instance |
|
||||||
|
| `dbutils_mongo/` | `db-start.sh` | Spin up a local MongoDB + Mongo Express via Docker |
|
||||||
|
|
||||||
|
## Running the Scripts
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Backup — interactive environment picker
|
||||||
|
cd dbdump_mongo && bash db-dump.sh
|
||||||
|
|
||||||
|
# Restore — interactive backup directory navigator
|
||||||
|
cd dbrestore_mongo && bash db-restore.sh
|
||||||
|
|
||||||
|
# Local dev database — Docker-based
|
||||||
|
cd dbutils_mongo && bash db-start.sh up # start
|
||||||
|
cd dbutils_mongo && bash db-start.sh down # stop
|
||||||
|
cd dbutils_mongo && bash db-start.sh status
|
||||||
|
cd dbutils_mongo && bash db-start.sh logs
|
||||||
|
cd dbutils_mongo && bash db-start.sh clean # remove volumes
|
||||||
|
cd dbutils_mongo && bash db-start.sh reconfigure
|
||||||
|
```
|
||||||
|
|
||||||
|
## Environment Setup
|
||||||
|
|
||||||
|
Each module requires a `.env` file (copied from the corresponding `.env.example`). The `.env` files are git-ignored. `dbdump_mongo` supports multiple named environments stored as `.env.<name>` files with `chmod 600` permissions.
|
||||||
|
|
||||||
|
## Architecture Patterns
|
||||||
|
|
||||||
|
All three scripts share the same conventions:
|
||||||
|
|
||||||
|
- **Sub-command dispatch**: a `main()` function routes `$1` to `cmd_<action>()` functions.
|
||||||
|
- **Colored output**: ANSI escape codes (`\033[...m`) for styled terminal output; consistent separator lines.
|
||||||
|
- **Prerequisite checks**: each script validates its required tools (`mongodump`, `mongorestore`, `docker`, `docker compose`) at startup and exits early with a clear message if missing.
|
||||||
|
- **Interactive prompts**: `read -p` / `select` menus guide the user through environment selection, directory navigation, and confirmation steps before any destructive action.
|
||||||
|
|
||||||
|
### dbdump_mongo — multi-environment credential model
|
||||||
|
|
||||||
|
Named environments are stored as `.env.<name>` files alongside the main `.env`. Credentials include `MONGO_USERNAME`, `MONGO_PASSWORD`, `MONGO_HOST`, `MONGO_PORT`, `APP_NAME`. Dumps land in `./dumps/<appName>/<yyyymmdd_hhmm>/`. The script generates MongoDB Atlas-compatible connection strings (ssl, replicaSet flags).
|
||||||
|
|
||||||
|
### dbrestore_mongo — backup directory navigation
|
||||||
|
|
||||||
|
The script walks through backup directory hierarchies interactively. It detects valid restore targets by checking for `.bson` files (`has_bson_files()`). Before executing `mongorestore`, it shows a summary of connection details and the selected backup path and requires explicit confirmation.
|
||||||
|
|
||||||
|
### dbutils_mongo — Docker Compose orchestration
|
||||||
|
|
||||||
|
Runs two containers on a `dbutils-network` bridge: MongoDB (configurable port, default `MONGO_PORT`) and Mongo Express (default port `8081`). Data is persisted in named volumes `mongodb-data` and `mongodb-config`. On first run, `setup_credentials()` prompts interactively and writes `.env`. The `mongo-init.js` initializer creates a `dataImportHistory` collection with indexes on `importDate` and `status`.
|
||||||
|
|
||||||
|
## External Dependencies
|
||||||
|
|
||||||
|
- `mongodump` / `mongorestore` — MongoDB Database Tools (must be installed separately)
|
||||||
|
- `docker` + `docker compose` (v2 plugin syntax)
|
||||||
|
- `bash` (scripts use `bash`-specific features, not POSIX `sh`)
|
||||||
@@ -1,3 +1,45 @@
|
|||||||
# adastra_scripts
|
# AdAstra Scripts
|
||||||
|
|
||||||
AdAstra Utility Scripts
|
A collection of utility scripts for AdAstra projects. Each script is self-contained and can be used independently.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
### MongoDB
|
||||||
|
|
||||||
|
| Script | Description |
|
||||||
|
|---|---|
|
||||||
|
| [`dbdump_mongo/`](dbdump_mongo/) | Backup MongoDB databases with multi-environment support (prod, uat, staging, …) |
|
||||||
|
| [`dbrestore_mongo/`](dbrestore_mongo/) | Restore a MongoDB backup with interactive directory navigation |
|
||||||
|
| [`dbutils_mongo/`](dbutils_mongo/) | Spin up a local MongoDB + Mongo Express instance via Docker |
|
||||||
|
|
||||||
|
#### Typical MongoDB workflow
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Backup from a remote MongoDB
|
||||||
|
cd dbdump_mongo && ./db-dump.sh dump
|
||||||
|
|
||||||
|
# 2. Start a local MongoDB instance
|
||||||
|
cd dbutils_mongo && ./db-start.sh up
|
||||||
|
|
||||||
|
# 3. Restore the backup locally
|
||||||
|
cd dbrestore_mongo && ./db-restore.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### File Sync
|
||||||
|
|
||||||
|
| Script | Description |
|
||||||
|
|---|---|
|
||||||
|
| [`dirsync/`](dirsync/) | Watch a local directory and sync changes to a remote host via SCP in real time |
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
Each script lists its own requirements in its README. Common dependencies:
|
||||||
|
|
||||||
|
- **Bash**
|
||||||
|
- **MongoDB Database Tools** (`mongodump` / `mongorestore`) — [download](https://www.mongodb.com/try/download/database-tools)
|
||||||
|
- **Docker & Docker Compose** (for `dbutils_mongo` only)
|
||||||
|
- **fswatch + ssh + scp** (for `dirsync` only)
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
Julien Gautier — AdAstra
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# MongoDB Dump Environment Configuration Example
|
||||||
|
# Copy this pattern to create environments: .env.prod, .env.uat, etc.
|
||||||
|
# DO NOT commit actual configuration files to version control
|
||||||
|
|
||||||
|
# Environment: example
|
||||||
|
# Created: 2026-04-14
|
||||||
|
|
||||||
|
# MongoDB credentials (no defaults - must be provided)
|
||||||
|
MONGO_USERNAME=admin_user
|
||||||
|
MONGO_PASSWORD=secure_password_here
|
||||||
|
MONGO_HOST=cluster0.mongodb.net
|
||||||
|
MONGO_PORT=27017
|
||||||
|
APP_NAME=my-app
|
||||||
|
|
||||||
|
# Note: The connection string will be constructed as:
|
||||||
|
# mongodb://<MONGO_USERNAME>:<MONGO_PASSWORD>@<MONGO_HOST>:<MONGO_PORT>/
|
||||||
|
# ?ssl=true&replicaSet=globaldb&retrywrites=false
|
||||||
|
# &maxIdleTimeMS=120000&appName=@<APP_NAME>@
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# Environment configuration files (contain sensitive credentials)
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
|
# Dump directories (can be large)
|
||||||
|
dumps/
|
||||||
|
*.dump
|
||||||
|
|
||||||
|
# OS files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
@@ -0,0 +1,219 @@
|
|||||||
|
# MongoDB Dump Utility
|
||||||
|
|
||||||
|
This directory contains a standalone tool for backing up MongoDB databases from remote servers.
|
||||||
|
It manages multiple environment configurations for easy switching between prod, uat, and other environments.
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### First Run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./db-dump.sh dump
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will detect no environments and guide you through creating one. Answer the prompts with:
|
||||||
|
- **Environment name** (required): e.g., `prod`, `uat`, `staging`
|
||||||
|
- **MongoDB username** (required): The admin user
|
||||||
|
- **MongoDB password** (required): The admin password
|
||||||
|
- **MongoDB host** (required): e.g., `cluster0.mongodb.net`
|
||||||
|
- **MongoDB port** (required): Usually `27017` or `10255`
|
||||||
|
- **Application name** (required): Used in connection string and dump folder name
|
||||||
|
|
||||||
|
### Subsequent Runs
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./db-dump.sh dump
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will show you a list of configured environments and let you choose which one to backup,
|
||||||
|
or create a new environment.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Perform a backup of a selected environment
|
||||||
|
./db-dump.sh dump
|
||||||
|
|
||||||
|
# List all configured environments
|
||||||
|
./db-dump.sh list
|
||||||
|
|
||||||
|
# Add a new environment
|
||||||
|
./db-dump.sh add
|
||||||
|
|
||||||
|
# Delete an environment
|
||||||
|
./db-dump.sh delete
|
||||||
|
|
||||||
|
# Show help
|
||||||
|
./db-dump.sh help
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. **Environment Selection**: On each run, you select from existing environments or create new ones
|
||||||
|
2. **Credential Storage**: Each environment's credentials are stored in `.env.<name>` files
|
||||||
|
3. **MongoDB Connection**: Connects using your credentials with MongoDB Atlas parameters (ssl, replicaSet, etc.)
|
||||||
|
4. **Dump Creation**: Uses `mongodump` to create a backup
|
||||||
|
5. **Timestamped Output**: Dumps are organized as `./dumps/<appName>/<yyyymmdd_hhmm>/`
|
||||||
|
|
||||||
|
## Configuration Files
|
||||||
|
|
||||||
|
Each environment is stored in a separate file:
|
||||||
|
|
||||||
|
```
|
||||||
|
.env.prod # Production environment
|
||||||
|
.env.uat # UAT environment
|
||||||
|
.env.staging # Staging environment (if created)
|
||||||
|
```
|
||||||
|
|
||||||
|
Each file contains:
|
||||||
|
```
|
||||||
|
MONGO_USERNAME=<username>
|
||||||
|
MONGO_PASSWORD=<password>
|
||||||
|
MONGO_HOST=<host>
|
||||||
|
MONGO_PORT=<port>
|
||||||
|
APP_NAME=<appName>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Directory Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
dbdump/
|
||||||
|
├── db-dump.sh # Main script
|
||||||
|
├── .env.prod # Production config (created by user)
|
||||||
|
├── .env.uat # UAT config (created by user)
|
||||||
|
├── .env.example # Example configuration
|
||||||
|
├── .gitignore # Git ignore rules
|
||||||
|
├── README.md # This file
|
||||||
|
└── dumps/ # Created automatically
|
||||||
|
├── prod/
|
||||||
|
│ ├── 20260414_1632/
|
||||||
|
│ │ ├── admin/
|
||||||
|
│ │ └── myapp/
|
||||||
|
│ └── 20260414_1645/
|
||||||
|
└── uat/
|
||||||
|
└── 20260414_1632/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Dump Output
|
||||||
|
|
||||||
|
Dumps are stored with the following structure:
|
||||||
|
|
||||||
|
```
|
||||||
|
dumps/<appName>/<yyyymmdd_hhmi>/
|
||||||
|
admin/ # System databases
|
||||||
|
config/
|
||||||
|
myapp/ # Application databases
|
||||||
|
system.profile/
|
||||||
|
```
|
||||||
|
|
||||||
|
Each backup preserves the complete database structure and is ready to be restored using `mongorestore`.
|
||||||
|
|
||||||
|
## Accessing Dumps
|
||||||
|
|
||||||
|
To view or restore a dump:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# List recent dumps
|
||||||
|
ls -lh dumps/prod/
|
||||||
|
|
||||||
|
# Restore a dump to local MongoDB
|
||||||
|
mongorestore --uri "mongodb://localhost:27017" dumps/prod/20260414_1632/
|
||||||
|
|
||||||
|
# Copy dump to another location
|
||||||
|
cp -r dumps/prod/20260414_1632/ /backup/prod-backup-20260414/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
- Configuration files have restricted permissions (600)
|
||||||
|
- Credentials are stored locally in `.env.*` files
|
||||||
|
- These files are git-ignored for security
|
||||||
|
- Never commit `.env.*` files to version control
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- **MongoDB Database Tools**: Download from https://www.mongodb.com/try/download/database-tools
|
||||||
|
- Specifically requires `mongodump` command
|
||||||
|
- Bash shell
|
||||||
|
- Network access to MongoDB server
|
||||||
|
|
||||||
|
## Installation of MongoDB Database Tools
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
```bash
|
||||||
|
brew tap mongodb/brew
|
||||||
|
brew install mongodb-database-tools
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linux (Ubuntu/Debian)
|
||||||
|
```bash
|
||||||
|
wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-x86_64-100.8.0.tgz
|
||||||
|
tar -xzf mongodb-database-tools-ubuntu2004-x86_64-100.8.0.tgz
|
||||||
|
sudo cp mongodb-database-tools-ubuntu2004-x86_64-100.8.0/bin/* /usr/local/bin/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
Download the MSI installer from https://www.mongodb.com/try/download/database-tools and run it.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### mongodump not found
|
||||||
|
```bash
|
||||||
|
# Check if MongoDB Database Tools is installed
|
||||||
|
mongodump --version
|
||||||
|
|
||||||
|
# If not installed, see "Installation" section above
|
||||||
|
```
|
||||||
|
|
||||||
|
### Connection refused
|
||||||
|
- Verify host and port are correct
|
||||||
|
- Check network connectivity to MongoDB server
|
||||||
|
- Ensure firewall allows access
|
||||||
|
|
||||||
|
### Authentication failed
|
||||||
|
- Verify username and password
|
||||||
|
- Check the user has admin permissions
|
||||||
|
- Confirm the `authSource=admin` parameter
|
||||||
|
|
||||||
|
### Port already displaying in error
|
||||||
|
The connection string is checked for errors. If you see connection errors, the script displays the exact MongoDB error message.
|
||||||
|
|
||||||
|
## Advanced Usage
|
||||||
|
|
||||||
|
### Manual mongodump command (for reference)
|
||||||
|
|
||||||
|
The script constructs and runs this command automatically:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mongodump --uri "mongodb://<username>:<password>@<host>:<port>/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@<appName>@" -o ./dumps/<appName>/<yyyymmdd_hhmm>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Scheduling automated backups
|
||||||
|
|
||||||
|
You can schedule regular backups using cron (Linux/macOS):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Add to crontab
|
||||||
|
crontab -e
|
||||||
|
|
||||||
|
# Daily dump at 3 AM for production environment
|
||||||
|
0 3 * * * cd /path/to/dbdump && ./db-dump.sh dump << EOF
|
||||||
|
1
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
For MongoDB connection issues, refer to:
|
||||||
|
- MongoDB Documentation: https://docs.mongodb.com/
|
||||||
|
- Connection String Reference: https://docs.mongodb.com/manual/reference/connection-string/
|
||||||
|
|
||||||
|
## About
|
||||||
|
|
||||||
|
**Author:** Julien Gautier ([jgautier.webdev@gmail.com](mailto:jgautier.webdev@gmail.com))
|
||||||
|
|
||||||
|
**Organization:** AdAstra
|
||||||
|
|
||||||
|
**Project:** adastra_scripts
|
||||||
|
|
||||||
|
This utility was created to enable efficient backup and versioning of MongoDB databases from remote servers for AdAstra projects.
|
||||||
Executable
+450
@@ -0,0 +1,450 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Author: Julien Gautier <jgautier.webdev@gmail.com>
|
||||||
|
# Organization: AdAstra
|
||||||
|
# Project: adastra_scripts
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
# MongoDB Dump Utility Script (Standalone)
|
||||||
|
#
|
||||||
|
# This script performs backups (dumps) of MongoDB databases from remote or local servers.
|
||||||
|
# It manages multiple environments (prod, uat, etc.) with stored credentials.
|
||||||
|
#
|
||||||
|
# Usage: ./db-dump.sh <command>
|
||||||
|
#
|
||||||
|
# Commands:
|
||||||
|
# dump Select environment and perform a dump
|
||||||
|
# list List all configured environments
|
||||||
|
# add Add a new environment
|
||||||
|
# delete Delete an environment
|
||||||
|
# help Show this help message
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# ./db-dump.sh dump
|
||||||
|
# ./db-dump.sh list
|
||||||
|
# ./db-dump.sh add
|
||||||
|
#
|
||||||
|
# Configuration:
|
||||||
|
# Each environment is stored in a separate .env.<environment> file.
|
||||||
|
# All dumps are stored in ./dumps/<appName>/<yyyymmdd_hhmm>/
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
DUMPS_DIR="${SCRIPT_DIR}/dumps"
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# Helper functions
|
||||||
|
print_info() {
|
||||||
|
echo -e "${BLUE}┣━${NC} ${CYAN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success() {
|
||||||
|
echo -e "${GREEN}✓ ${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo -e "${RED}✗ ${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}⚠ ${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_separator() {
|
||||||
|
echo -e "${BLUE}┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_separator_up() {
|
||||||
|
echo -e "${BLUE}┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_separator_down() {
|
||||||
|
echo -e "${BLUE}┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_section() {
|
||||||
|
echo
|
||||||
|
print_separator_up
|
||||||
|
print_info "$1"
|
||||||
|
print_separator_down
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
check_mongodump() {
|
||||||
|
if ! command -v mongodump &> /dev/null; then
|
||||||
|
print_error "mongodump is not installed or not in PATH"
|
||||||
|
print_info "Install MongoDB Database Tools from: https://www.mongodb.com/try/download/database-tools"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
print_success "mongodump found: $(mongodump --version)"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_environments() {
|
||||||
|
local envs=()
|
||||||
|
for env_file in "$SCRIPT_DIR"/.env.*; do
|
||||||
|
if [[ -f "$env_file" ]]; then
|
||||||
|
local env_name=$(basename "$env_file" | sed 's/^\.env\.//')
|
||||||
|
# Exclude the example file
|
||||||
|
if [[ "$env_name" != "example" ]]; then
|
||||||
|
envs+=("$env_name")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "${envs[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
env_file_path() {
|
||||||
|
echo "${SCRIPT_DIR}/.env.$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
create_environment() {
|
||||||
|
print_section "Create New Environment"
|
||||||
|
|
||||||
|
# Check if environment name already exists
|
||||||
|
read -p "Enter environment name (prod, uat, etc.): " env_name
|
||||||
|
env_name="${env_name,,}" # Convert to lowercase
|
||||||
|
|
||||||
|
if [[ -z "$env_name" ]]; then
|
||||||
|
print_error "Environment name cannot be empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f "$(env_file_path "$env_name")" ]]; then
|
||||||
|
print_error "Environment '$env_name' already exists"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_info "Enter MongoDB connection details for '$env_name'"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Read credentials (no defaults)
|
||||||
|
read -p "MongoDB username: " mongo_username
|
||||||
|
if [[ -z "$mongo_username" ]]; then
|
||||||
|
print_error "Username cannot be empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -sp "MongoDB password: " mongo_password
|
||||||
|
echo
|
||||||
|
if [[ -z "$mongo_password" ]]; then
|
||||||
|
print_error "Password cannot be empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -p "MongoDB host (e.g., cluster0.mongodb.net): " mongo_host
|
||||||
|
if [[ -z "$mongo_host" ]]; then
|
||||||
|
print_error "Host cannot be empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -p "MongoDB port (e.g., 27017): " mongo_port
|
||||||
|
if [[ -z "$mongo_port" ]]; then
|
||||||
|
print_error "Port cannot be empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -p "Application name (appName): " app_name
|
||||||
|
if [[ -z "$app_name" ]]; then
|
||||||
|
print_error "Application name cannot be empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create .env file for this environment
|
||||||
|
local env_file=$(env_file_path "$env_name")
|
||||||
|
cat > "$env_file" << EOF
|
||||||
|
# Environment: $env_name
|
||||||
|
# Created: $(date)
|
||||||
|
MONGO_USERNAME=${mongo_username}
|
||||||
|
MONGO_PASSWORD=${mongo_password}
|
||||||
|
MONGO_HOST=${mongo_host}
|
||||||
|
MONGO_PORT=${mongo_port}
|
||||||
|
APP_NAME=${app_name}
|
||||||
|
EOF
|
||||||
|
chmod 600 "$env_file" # Restrict permissions for security
|
||||||
|
|
||||||
|
print_success "Environment '$env_name' created successfully"
|
||||||
|
print_info "Configuration stored in: $(basename "$env_file")"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Global variable to hold selected environment
|
||||||
|
SELECTED_ENVIRONMENT=""
|
||||||
|
|
||||||
|
select_environment() {
|
||||||
|
SELECTED_ENVIRONMENT=""
|
||||||
|
local envs=($(get_environments))
|
||||||
|
local count=${#envs[@]}
|
||||||
|
|
||||||
|
print_separator_up
|
||||||
|
|
||||||
|
if [[ $count -eq 0 ]]; then
|
||||||
|
print_info "No Environments Configured"
|
||||||
|
print_separator
|
||||||
|
echo
|
||||||
|
print_warning "No existing environments found"
|
||||||
|
echo
|
||||||
|
echo " 1) Create a new environment"
|
||||||
|
echo " 2) Exit"
|
||||||
|
echo
|
||||||
|
echo -n "Enter your choice (1-2): "
|
||||||
|
read choice
|
||||||
|
|
||||||
|
if [[ "$choice" == "1" ]]; then
|
||||||
|
if create_environment; then
|
||||||
|
# After creating an environment, recursively call to select it
|
||||||
|
select_environment
|
||||||
|
return $?
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_info "Select Environment"
|
||||||
|
print_separator_down
|
||||||
|
echo
|
||||||
|
|
||||||
|
for i in "${!envs[@]}"; do
|
||||||
|
echo " $((i + 1))) ${envs[$i]}"
|
||||||
|
done
|
||||||
|
echo " $((count + 1))) Create new environment"
|
||||||
|
echo
|
||||||
|
echo -n "Enter your choice (1-$((count + 1))): "
|
||||||
|
read choice
|
||||||
|
|
||||||
|
if [[ "$choice" =~ ^[0-9]+$ ]] && [[ $choice -ge 1 ]] && [[ $choice -le $((count + 1)) ]]; then
|
||||||
|
if [[ $choice -eq $((count + 1)) ]]; then
|
||||||
|
if create_environment; then
|
||||||
|
# After creating an environment, recursively call to select it
|
||||||
|
select_environment
|
||||||
|
return $?
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
SELECTED_ENVIRONMENT="${envs[$((choice - 1))]}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_error "Invalid choice"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
load_environment() {
|
||||||
|
local env_name="$1"
|
||||||
|
local env_file=$(env_file_path "$env_name")
|
||||||
|
|
||||||
|
if [[ ! -f "$env_file" ]]; then
|
||||||
|
print_error "Environment file not found: $env_file"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source "$env_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
perform_dump() {
|
||||||
|
local env_name="$1"
|
||||||
|
|
||||||
|
load_environment "$env_name" || return 1
|
||||||
|
|
||||||
|
print_section "MongoDB Dump: $env_name"
|
||||||
|
|
||||||
|
# Create output directory with timestamp
|
||||||
|
local timestamp=$(date +%Y%m%d_%H%M)
|
||||||
|
local output_dir="${DUMPS_DIR}/${APP_NAME}/${timestamp}"
|
||||||
|
|
||||||
|
mkdir -p "$output_dir"
|
||||||
|
|
||||||
|
print_separator_up
|
||||||
|
print_info "Environment: $env_name"
|
||||||
|
print_info "App Name: $APP_NAME"
|
||||||
|
print_info "Host: $MONGO_HOST:$MONGO_PORT"
|
||||||
|
print_info "Output: $output_dir"
|
||||||
|
print_separator_down
|
||||||
|
|
||||||
|
# Construct connection string
|
||||||
|
local connection_uri="mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@${APP_NAME}@"
|
||||||
|
|
||||||
|
# Perform dump
|
||||||
|
if mongodump --uri "$connection_uri" -o "$output_dir" 2>&1; then
|
||||||
|
print_success "Dump completed successfully"
|
||||||
|
print_info "Output directory: $output_dir"
|
||||||
|
|
||||||
|
# Show dump summary
|
||||||
|
local dump_size=$(du -sh "$output_dir" | cut -f1)
|
||||||
|
print_info "Total size: $dump_size"
|
||||||
|
else
|
||||||
|
print_error "Dump failed"
|
||||||
|
print_warning "Removing incomplete dump directory..."
|
||||||
|
rm -rf "$output_dir"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_dump() {
|
||||||
|
print_separator_up
|
||||||
|
print_info "MongoDB Dump Utility"
|
||||||
|
print_separator_down
|
||||||
|
|
||||||
|
check_mongodump
|
||||||
|
|
||||||
|
select_environment
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
print_error "No environment selected"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if perform_dump "$SELECTED_ENVIRONMENT"; then
|
||||||
|
print_success "Dump operation completed"
|
||||||
|
else
|
||||||
|
print_error "Dump operation failed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_list() {
|
||||||
|
print_section "Configured Environments"
|
||||||
|
|
||||||
|
local envs=($(get_environments))
|
||||||
|
|
||||||
|
if [[ ${#envs[@]} -eq 0 ]]; then
|
||||||
|
print_warning "No environments configured yet"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
for env in "${envs[@]}"; do
|
||||||
|
local env_file=$(env_file_path "$env")
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source "$env_file"
|
||||||
|
echo " • $env"
|
||||||
|
echo " Host: $MONGO_HOST:$MONGO_PORT"
|
||||||
|
echo " App: $APP_NAME"
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_add() {
|
||||||
|
if create_environment; then
|
||||||
|
print_success "Environment added successfully"
|
||||||
|
else
|
||||||
|
print_error "Failed to add environment"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_delete() {
|
||||||
|
print_section "Delete Environment"
|
||||||
|
|
||||||
|
local envs=($(get_environments))
|
||||||
|
|
||||||
|
if [[ ${#envs[@]} -eq 0 ]]; then
|
||||||
|
print_warning "No environments configured"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
for i in "${!envs[@]}"; do
|
||||||
|
echo " $((i + 1))) ${envs[$i]}"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
|
||||||
|
read -p "Enter environment number to delete: " choice
|
||||||
|
|
||||||
|
if [[ "$choice" =~ ^[0-9]+$ ]] && [[ $choice -ge 1 ]] && [[ $choice -le ${#envs[@]} ]]; then
|
||||||
|
local env_name="${envs[$((choice - 1))]}"
|
||||||
|
read -p "Confirm deletion of '$env_name'? (yes/no): " confirm
|
||||||
|
|
||||||
|
if [[ "$confirm" == "yes" ]]; then
|
||||||
|
local env_file=$(env_file_path "$env_name")
|
||||||
|
rm -f "$env_file"
|
||||||
|
print_success "Environment '$env_name' deleted"
|
||||||
|
else
|
||||||
|
print_info "Deletion cancelled"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
print_error "Invalid choice"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_help() {
|
||||||
|
cat << EOF
|
||||||
|
|
||||||
|
MongoDB Dump Utility Script (Standalone)
|
||||||
|
|
||||||
|
Usage: ./db-dump.sh <command>
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
dump Select an environment and perform a backup dump
|
||||||
|
list List all configured environments
|
||||||
|
add Add a new environment configuration
|
||||||
|
delete Delete an environment configuration
|
||||||
|
help Show this help message
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
./db-dump.sh dump # Interactive environment selection and dump
|
||||||
|
./db-dump.sh list # Show all environments
|
||||||
|
./db-dump.sh add # Add new environment
|
||||||
|
./db-dump.sh delete # Remove an environment
|
||||||
|
|
||||||
|
Environment Configuration:
|
||||||
|
- Each environment is stored in a separate .env.<name> file
|
||||||
|
- Credentials are encrypted (file permissions: 600)
|
||||||
|
- Supported environments: prod, uat, dev, staging, etc.
|
||||||
|
|
||||||
|
Dump Output:
|
||||||
|
- Dumps are stored in: ./dumps/<appName>/<yyyymmdd_hhmm>/
|
||||||
|
- Each dump is timestamped for easy identification
|
||||||
|
- Connection string includes MongoDB Atlas parameters
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
- MongoDB Database Tools (mongodump)
|
||||||
|
- Bash shell
|
||||||
|
|
||||||
|
MongoDB Connection String Format:
|
||||||
|
mongodb://<username>:<password>@<host>:<port>/
|
||||||
|
?ssl=true&replicaSet=globaldb&retrywrites=false
|
||||||
|
&maxIdleTimeMS=120000&appName=@<appName>@
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main
|
||||||
|
COMMAND="${1:-help}"
|
||||||
|
|
||||||
|
case "$COMMAND" in
|
||||||
|
dump)
|
||||||
|
cmd_dump
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
cmd_list
|
||||||
|
;;
|
||||||
|
add)
|
||||||
|
cmd_add
|
||||||
|
;;
|
||||||
|
delete)
|
||||||
|
cmd_delete
|
||||||
|
;;
|
||||||
|
help|--help|-h)
|
||||||
|
cmd_help
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "Unknown command: $COMMAND"
|
||||||
|
echo
|
||||||
|
cmd_help
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# MongoDB Restore Configuration
|
||||||
|
# Copy this file to .env and update with your values
|
||||||
|
# This configuration should match your local MongoDB instance
|
||||||
|
|
||||||
|
# MongoDB credentials (for the target database)
|
||||||
|
MONGO_USERNAME=admin
|
||||||
|
MONGO_PASSWORD=password
|
||||||
|
MONGO_HOST=localhost
|
||||||
|
MONGO_PORT=27017
|
||||||
|
MONGO_DATABASE=adastradb
|
||||||
|
MONGO_AUTHSOURCE=admin
|
||||||
|
|
||||||
|
# Note: The connection string will be constructed as:
|
||||||
|
# mongodb://<MONGO_USERNAME>:<MONGO_PASSWORD>@<MONGO_HOST>:<MONGO_PORT>/<MONGO_DATABASE>?authSource=<MONGO_AUTHSOURCE>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Environment configuration file (contains sensitive credentials)
|
||||||
|
.env
|
||||||
|
!.env.example
|
||||||
|
|
||||||
|
# OS files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
# MongoDB Restore Utility (Standalone)
|
||||||
|
|
||||||
|
This directory contains a standalone tool for restoring MongoDB database backups created with `db-dump.sh`.
|
||||||
|
It provides interactive navigation through backup directories and restores them to a configured MongoDB instance.
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### 1. Configure Connection Details
|
||||||
|
|
||||||
|
Copy the example configuration:
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
Edit `.env` with your MongoDB connection details:
|
||||||
|
```
|
||||||
|
MONGO_USERNAME=admin
|
||||||
|
MONGO_PASSWORD=password
|
||||||
|
MONGO_HOST=localhost
|
||||||
|
MONGO_PORT=27017
|
||||||
|
MONGO_DATABASE=adastradb
|
||||||
|
MONGO_AUTHSOURCE=admin
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Restore a Backup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./db-restore.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will:
|
||||||
|
1. Verify MongoDB tools are installed
|
||||||
|
2. Load your configuration
|
||||||
|
3. Ask for the path to your backups directory
|
||||||
|
4. Guide you through the directory structure
|
||||||
|
5. Show a summary of what will be restored
|
||||||
|
6. Ask for confirmation
|
||||||
|
7. Restore the backup
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
The script requires a `.env` file with these variables:
|
||||||
|
- `MONGO_USERNAME` - MongoDB admin username
|
||||||
|
- `MONGO_PASSWORD` - MongoDB admin password
|
||||||
|
- `MONGO_HOST` - MongoDB server hostname/IP
|
||||||
|
- `MONGO_PORT` - MongoDB server port
|
||||||
|
- `MONGO_DATABASE` - Target database name
|
||||||
|
- `MONGO_AUTHSOURCE` - Authentication source (usually `admin`)
|
||||||
|
|
||||||
|
### Interactive Navigation
|
||||||
|
|
||||||
|
The script intelligently navigates through your backup directory structure:
|
||||||
|
|
||||||
|
```
|
||||||
|
dumps/
|
||||||
|
├── prod/ ← Choose this
|
||||||
|
│ ├── 20260414_1632/ ← Then this
|
||||||
|
│ │ └── (database folders) ← Then this
|
||||||
|
│ └── 20260414_1645/
|
||||||
|
└── uat/
|
||||||
|
└── 20260414_1700/
|
||||||
|
```
|
||||||
|
|
||||||
|
At each level, the script:
|
||||||
|
1. Shows available subdirectories
|
||||||
|
2. Asks you to choose one
|
||||||
|
3. Continues until it finds `.bson` files (backup data)
|
||||||
|
|
||||||
|
### Backup Detection
|
||||||
|
|
||||||
|
The script automatically stops navigation when it finds a directory containing `.bson` files, which are the actual backup data files.
|
||||||
|
|
||||||
|
Example backup structure:
|
||||||
|
```
|
||||||
|
~/Works/dbdump/dumps/
|
||||||
|
└── bo-uat-cosmodb/
|
||||||
|
└── 20260414_1732/
|
||||||
|
└── admin/ ← BSON files here
|
||||||
|
├── system.profile.bson
|
||||||
|
└── system.version.bson
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example Use Case
|
||||||
|
|
||||||
|
Given this backup structure:
|
||||||
|
```
|
||||||
|
~/Works/dbdump/dumps/
|
||||||
|
├── bo-prod-cosmodb/
|
||||||
|
│ └── 20260414_1600/
|
||||||
|
│ └── AdAstra/
|
||||||
|
│ ├── collection1.bson
|
||||||
|
│ └── collection1.metadata.json
|
||||||
|
└── bo-uat-cosmodb/
|
||||||
|
└── 20260414_1732/
|
||||||
|
└── AdAstra/
|
||||||
|
├── orders.bson
|
||||||
|
└── orders.metadata.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Restore process:
|
||||||
|
```bash
|
||||||
|
./db-restore.sh
|
||||||
|
|
||||||
|
# Script asks: Dumps path: ~/Works/dbdump/dumps
|
||||||
|
# Shows: 1) bo-prod-cosmodb 2) bo-uat-cosmodb
|
||||||
|
# You choose: 2
|
||||||
|
# Shows: 1) 20260414_1732
|
||||||
|
# You choose: 1
|
||||||
|
# Shows: 1) AdAstra
|
||||||
|
# You choose: 1
|
||||||
|
# Script finds BSON files and shows summary
|
||||||
|
```
|
||||||
|
|
||||||
|
## Restore Summary
|
||||||
|
|
||||||
|
Before executing the restore, the script displays:
|
||||||
|
|
||||||
|
```
|
||||||
|
MongoDB Connection:
|
||||||
|
Host: localhost
|
||||||
|
Port: 27017
|
||||||
|
Username: admin
|
||||||
|
Database: adastradb
|
||||||
|
AuthSource: admin
|
||||||
|
|
||||||
|
Backup Source:
|
||||||
|
Location: /home/user/Works/dbdump/dumps/bo-uat-cosmodb/20260414_1732
|
||||||
|
Backup files: 42
|
||||||
|
Total size: 250M
|
||||||
|
```
|
||||||
|
|
||||||
|
You must confirm with "yes" to proceed.
|
||||||
|
|
||||||
|
## Connection String
|
||||||
|
|
||||||
|
The script constructs the MongoDB connection string as:
|
||||||
|
|
||||||
|
```
|
||||||
|
mongodb://<username>:<password>@<host>:<port>/<database>?authSource=<authSource>
|
||||||
|
```
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
mongodb://admin:password@localhost:27017/adastradb?authSource=admin
|
||||||
|
```
|
||||||
|
|
||||||
|
## Directory Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
dbrestore/
|
||||||
|
├── db-restore.sh # Main script
|
||||||
|
├── .env # Configuration (created by you, git-ignored)
|
||||||
|
├── .env.example # Example configuration
|
||||||
|
├── .gitignore # Git ignore rules
|
||||||
|
└── README.md # This file
|
||||||
|
```
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
- Configuration file (`.env`) has restricted permissions
|
||||||
|
- Contains sensitive credentials (username, password)
|
||||||
|
- Never commit actual `.env` file to version control
|
||||||
|
- Use `.env.example` as template
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- **MongoDB Database Tools**: Download from https://www.mongodb.com/try/download/database-tools
|
||||||
|
- Specifically requires `mongorestore` command
|
||||||
|
- Bash shell
|
||||||
|
- Network access to MongoDB server
|
||||||
|
- Backup files created by `db-dump.sh` or `mongodump`
|
||||||
|
|
||||||
|
## Installation of MongoDB Database Tools
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
```bash
|
||||||
|
brew tap mongodb/brew
|
||||||
|
brew install mongodb-database-tools
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linux (Ubuntu/Debian)
|
||||||
|
```bash
|
||||||
|
wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-x86_64-100.8.0.tgz
|
||||||
|
tar -xzf mongodb-database-tools-ubuntu2004-x86_64-100.8.0.tgz
|
||||||
|
sudo cp mongodb-database-tools-ubuntu2004-x86_64-100.8.0/bin/* /usr/local/bin/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
Download the MSI installer from https://www.mongodb.com/try/download/database-tools and run it.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### mongorestore not found
|
||||||
|
```bash
|
||||||
|
# Check if MongoDB Database Tools is installed
|
||||||
|
mongorestore --version
|
||||||
|
|
||||||
|
# If not installed, see "Installation" section above
|
||||||
|
```
|
||||||
|
|
||||||
|
### .env file not found
|
||||||
|
```bash
|
||||||
|
# Copy the example configuration
|
||||||
|
cp .env.example .env
|
||||||
|
|
||||||
|
# Edit with your values
|
||||||
|
nano .env # or your favorite editor
|
||||||
|
```
|
||||||
|
|
||||||
|
### Connection refused
|
||||||
|
- Verify host and port are correct
|
||||||
|
- Check network connectivity to MongoDB server
|
||||||
|
- Ensure firewall allows access
|
||||||
|
- Verify MongoDB service is running (if local)
|
||||||
|
|
||||||
|
### Authentication failed
|
||||||
|
- Verify username and password in `.env`
|
||||||
|
- Check user has sufficient permissions
|
||||||
|
- Confirm `authSource` is correct (usually `admin`)
|
||||||
|
|
||||||
|
### No BSON files found
|
||||||
|
- Make sure you're pointing to the root of dumps directory
|
||||||
|
- Navigate through subdirectories until you reach the folder with actual backup files
|
||||||
|
- BSON files are typically deep in the directory structure
|
||||||
|
|
||||||
|
## Manual Restore Command
|
||||||
|
|
||||||
|
For reference, here's the command the script executes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mongorestore --uri "mongodb://user:pass@host:port/db?authSource=admin" /path/to/dumps
|
||||||
|
```
|
||||||
|
|
||||||
|
## Related Tools
|
||||||
|
|
||||||
|
- **`dbutils/db-start.sh`** - Start MongoDB in Docker for restoring locally
|
||||||
|
- **`dbdump/db-dump.sh`** - Create backups from remote MongoDB servers
|
||||||
|
- **`dbrestore/db-restore.sh`** - Restore backups to a MongoDB instance (this tool)
|
||||||
|
|
||||||
|
## Workflow Example
|
||||||
|
|
||||||
|
Complete workflow to backup and restore:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Backup from production MongoDB (in dbdump folder)
|
||||||
|
cd ~/Works/dbdump
|
||||||
|
./db-dump.sh dump
|
||||||
|
# Select prod environment and wait for backup
|
||||||
|
|
||||||
|
# 2. Start local MongoDB (in dbutils folder)
|
||||||
|
cd ~/Works/dbutils
|
||||||
|
./db-start.sh up
|
||||||
|
|
||||||
|
# 3. Restore backup locally (in dbrestore folder)
|
||||||
|
cd ~/Works/dbrestore
|
||||||
|
./db-restore.sh
|
||||||
|
# Navigate to the backup created in step 1 and restore
|
||||||
|
```
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
For more information:
|
||||||
|
- MongoDB Documentation: https://docs.mongodb.com/
|
||||||
|
- mongorestore Manual: https://docs.mongodb.com/database-tools/mongorestore/
|
||||||
|
- Connection String Reference: https://docs.mongodb.com/manual/reference/connection-string/
|
||||||
|
|
||||||
|
## About
|
||||||
|
|
||||||
|
**Author:** Julien Gautier ([jgautier.webdev@gmail.com](mailto:jgautier.webdev@gmail.com))
|
||||||
|
|
||||||
|
**Organization:** AdAstra
|
||||||
|
|
||||||
|
**Project:** adastra_scripts
|
||||||
|
|
||||||
|
This utility was created to simplify the restoration of MongoDB database backups to local development environments for AdAstra projects.
|
||||||
Executable
+312
@@ -0,0 +1,312 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Author: Julien Gautier <jgautier.webdev@gmail.com>
|
||||||
|
# Organization: AdAstra
|
||||||
|
# Project: adastra_scripts
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
# MongoDB Restore Utility Script (Standalone)
|
||||||
|
#
|
||||||
|
# This script restores MongoDB database dumps from backup files.
|
||||||
|
# It provides interactive navigation through dump directories and restores
|
||||||
|
# to a configured MongoDB instance.
|
||||||
|
#
|
||||||
|
# Usage: ./db-restore.sh
|
||||||
|
#
|
||||||
|
# Configuration:
|
||||||
|
# Requires .env file with MongoDB connection details:
|
||||||
|
# - MONGO_USERNAME
|
||||||
|
# - MONGO_PASSWORD
|
||||||
|
# - MONGO_HOST
|
||||||
|
# - MONGO_PORT
|
||||||
|
# - MONGO_DATABASE
|
||||||
|
# - MONGO_AUTHSOURCE
|
||||||
|
#
|
||||||
|
# Example command (what the script executes):
|
||||||
|
# mongorestore --uri "mongodb://user:pass@host:port/db?authSource=admin" /path/to/dumps
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
ENV_FILE="${SCRIPT_DIR}/.env"
|
||||||
|
|
||||||
|
# Global variables
|
||||||
|
SELECTED_DUMP_PATH=""
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# Helper functions
|
||||||
|
print_info() {
|
||||||
|
echo -e "${BLUE}┣━${NC} ${CYAN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success() {
|
||||||
|
echo -e "${GREEN}✓ ${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo -e "${RED}✗ ${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}⚠ ${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_separator() {
|
||||||
|
echo -e "${BLUE}┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_separator_up() {
|
||||||
|
echo -e "${BLUE}┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_separator_down() {
|
||||||
|
echo -e "${BLUE}┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_section() {
|
||||||
|
echo
|
||||||
|
print_separator_up
|
||||||
|
print_info "$1"
|
||||||
|
print_separator_down
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
check_mongorestore() {
|
||||||
|
if ! command -v mongorestore &> /dev/null; then
|
||||||
|
print_error "mongorestore is not installed or not in PATH"
|
||||||
|
print_info "Install MongoDB Database Tools from: https://www.mongodb.com/try/download/database-tools"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
print_success "mongorestore found: $(mongorestore --version | head -1)"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_env_file() {
|
||||||
|
if [[ ! -f "$ENV_FILE" ]]; then
|
||||||
|
print_error "Configuration file not found: $ENV_FILE"
|
||||||
|
print_info "Please create .env file with the following variables:"
|
||||||
|
print_info " MONGO_USERNAME=<username>"
|
||||||
|
print_info " MONGO_PASSWORD=<password>"
|
||||||
|
print_info " MONGO_HOST=<host>"
|
||||||
|
print_info " MONGO_PORT=<port>"
|
||||||
|
print_info " MONGO_DATABASE=<database>"
|
||||||
|
print_info " MONGO_AUTHSOURCE=<authSource>"
|
||||||
|
print_info "You can copy from .env.example"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
load_config() {
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source "$ENV_FILE"
|
||||||
|
|
||||||
|
# Validate required variables
|
||||||
|
if [[ -z "$MONGO_USERNAME" ]] || [[ -z "$MONGO_PASSWORD" ]] || [[ -z "$MONGO_HOST" ]] || \
|
||||||
|
[[ -z "$MONGO_PORT" ]] || [[ -z "$MONGO_DATABASE" ]] || [[ -z "$MONGO_AUTHSOURCE" ]]; then
|
||||||
|
print_error "Missing required configuration variables in .env file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
has_bson_files() {
|
||||||
|
local dir="$1"
|
||||||
|
[[ -n $(find "$dir" -maxdepth 1 -type f -name "*.bson" 2>/dev/null | head -1) ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
has_subdirectories() {
|
||||||
|
local dir="$1"
|
||||||
|
[[ -n $(find "$dir" -maxdepth 1 -type d ! -name "." ! -name ".." 2>/dev/null | head -1) ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
navigate_to_dump() {
|
||||||
|
SELECTED_DUMP_PATH=""
|
||||||
|
local current_path="$1"
|
||||||
|
|
||||||
|
# Expand ~ in path
|
||||||
|
current_path="${current_path/#\~/$HOME}"
|
||||||
|
|
||||||
|
# Check if path exists
|
||||||
|
if [[ ! -d "$current_path" ]]; then
|
||||||
|
print_error "Path does not exist: $current_path"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If this directory has BSON files, we're at the right level
|
||||||
|
if has_bson_files "$current_path"; then
|
||||||
|
SELECTED_DUMP_PATH="$current_path"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If no subdirectories and no BSON files, this isn't a valid dump directory
|
||||||
|
if ! has_subdirectories "$current_path"; then
|
||||||
|
print_error "No BSON files found and no subdirectories in: $current_path"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Navigate through subdirectories
|
||||||
|
while true; do
|
||||||
|
print_separator_up
|
||||||
|
print_info "Select Dump Directory"
|
||||||
|
print_separator_down
|
||||||
|
echo
|
||||||
|
print_info "Current location: $current_path"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Get list of subdirectories
|
||||||
|
local subdirs=()
|
||||||
|
local count=0
|
||||||
|
|
||||||
|
# Read subdirectories into array (null-terminated, excluding . and ..)
|
||||||
|
while IFS= read -r -d '' subdir; do
|
||||||
|
subdirs+=("$subdir")
|
||||||
|
echo " $((++count))) $(basename "$subdir")"
|
||||||
|
done < <(find "$current_path" -maxdepth 1 -mindepth 1 -type d -print0 | sort -z)
|
||||||
|
|
||||||
|
if [[ $count -eq 0 ]]; then
|
||||||
|
print_error "No subdirectories found in: $current_path"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "Enter your choice (1-$count): "
|
||||||
|
read choice
|
||||||
|
|
||||||
|
if [[ "$choice" =~ ^[0-9]+$ ]] && [[ $choice -ge 1 ]] && [[ $choice -le $count ]]; then
|
||||||
|
current_path="${subdirs[$((choice - 1))]}"
|
||||||
|
|
||||||
|
# Check if this directory has BSON files
|
||||||
|
if has_bson_files "$current_path"; then
|
||||||
|
SELECTED_DUMP_PATH="$current_path"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If no more subdirectories and no BSON files, error
|
||||||
|
if ! has_subdirectories "$current_path"; then
|
||||||
|
print_error "No BSON files found in: $current_path"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
# Continue loop to show next level
|
||||||
|
else
|
||||||
|
print_error "Invalid choice"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
get_backup_summary() {
|
||||||
|
local dump_path="$1"
|
||||||
|
local bson_count=$(find "$dump_path" -name "*.bson" -type f 2>/dev/null | wc -l)
|
||||||
|
local total_size=$(du -sh "$dump_path" 2>/dev/null | cut -f1)
|
||||||
|
|
||||||
|
echo "Backup files: $bson_count"
|
||||||
|
echo "Total size: $total_size"
|
||||||
|
}
|
||||||
|
|
||||||
|
show_summary() {
|
||||||
|
local dump_path="$1"
|
||||||
|
|
||||||
|
print_section "Restore Summary"
|
||||||
|
|
||||||
|
echo "MongoDB Connection:"
|
||||||
|
echo " Host: $MONGO_HOST"
|
||||||
|
echo " Port: $MONGO_PORT"
|
||||||
|
echo " Username: $MONGO_USERNAME"
|
||||||
|
echo " Database: $MONGO_DATABASE"
|
||||||
|
echo " AuthSource: $MONGO_AUTHSOURCE"
|
||||||
|
echo
|
||||||
|
echo "Backup Source:"
|
||||||
|
echo " Location: $dump_path"
|
||||||
|
echo " $(get_backup_summary "$dump_path")"
|
||||||
|
echo
|
||||||
|
echo "Connection string:"
|
||||||
|
echo " mongodb://<username>:<password>@$MONGO_HOST:$MONGO_PORT/$MONGO_DATABASE?authSource=$MONGO_AUTHSOURCE"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
confirm_restore() {
|
||||||
|
echo -n "Do you want to proceed with the restore? (yes/no): "
|
||||||
|
read response
|
||||||
|
[[ "$response" == "yes" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
perform_restore() {
|
||||||
|
local dump_path="$1"
|
||||||
|
|
||||||
|
print_separator_up
|
||||||
|
print_info "Starting MongoDB Restore..."
|
||||||
|
print_separator_down
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Construct connection string
|
||||||
|
local connection_uri="mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/${MONGO_DATABASE}?authSource=${MONGO_AUTHSOURCE}"
|
||||||
|
|
||||||
|
# Perform restore
|
||||||
|
if mongorestore --uri "$connection_uri" "$dump_path" 2>&1; then
|
||||||
|
print_success "Restore completed successfully"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
print_error "Restore operation failed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
print_separator_up
|
||||||
|
print_info "MongoDB Restore Utility"
|
||||||
|
print_separator_down
|
||||||
|
|
||||||
|
# Initial checks
|
||||||
|
check_mongorestore
|
||||||
|
check_env_file
|
||||||
|
load_config
|
||||||
|
|
||||||
|
print_success "Configuration loaded"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Ask for initial dump path
|
||||||
|
print_info "Enter the path to the dumps directory"
|
||||||
|
echo " Example: ~/Works/dbdump/dumps"
|
||||||
|
echo
|
||||||
|
echo -n "Dumps path: "
|
||||||
|
read dumps_path
|
||||||
|
|
||||||
|
if [[ -z "$dumps_path" ]]; then
|
||||||
|
print_error "Dumps path cannot be empty"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Navigate to the correct dump directory
|
||||||
|
print_info "Navigating to backup location..."
|
||||||
|
navigate_to_dump "$dumps_path"
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
print_error "Failed to select backup directory"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Show summary of what will be restored
|
||||||
|
show_summary "$SELECTED_DUMP_PATH"
|
||||||
|
|
||||||
|
# Ask for confirmation
|
||||||
|
if ! confirm_restore; then
|
||||||
|
print_info "Restore operation cancelled"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Perform the restore
|
||||||
|
if perform_restore "$SELECTED_DUMP_PATH"; then
|
||||||
|
print_success "Restore operation completed"
|
||||||
|
else
|
||||||
|
print_error "Restore operation failed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Author: Julien Gautier <jgautier.webdev@gmail.com>
|
# Author: Julien Gautier <jgautier.webdev@gmail.com>
|
||||||
# Organization: AdAstra
|
# Organization: AdAstra
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
# Directory Sync Utility
|
||||||
|
|
||||||
|
This directory contains a tool for syncing a local directory to a remote host in real time.
|
||||||
|
It watches for file changes and transfers them immediately via SCP, making it useful for
|
||||||
|
live development on a remote server.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
| Script | Description |
|
||||||
|
|---|---|
|
||||||
|
| `dir-sync.sh` | Improved version — recommended |
|
||||||
|
| `scpsync.sh` | Original version |
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./dir-sync.sh -s /path/to/local/dir/ -d /path/to/remote/dir/ -r sshhost
|
||||||
|
```
|
||||||
|
|
||||||
|
The script starts watching the local directory immediately. Press **Ctrl+C** to stop —
|
||||||
|
it will reset the remote repository (`git reset --hard`) and clear the remote cache before exiting.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
| Option | Description |
|
||||||
|
|---|---|
|
||||||
|
| `-s, --source <path>` | Local directory absolute path |
|
||||||
|
| `-d, --dest <path>` | Remote directory absolute path |
|
||||||
|
| `-r, --remote-host <h>` | Remote SSH host (as configured in `~/.ssh/config`) |
|
||||||
|
| `-h, --help` | Print help |
|
||||||
|
|
||||||
|
If an option is omitted, the script falls back to the default values defined at the top of the script.
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
1. **File watching**: `fswatch` monitors the source directory for any change, excluding `.git/`
|
||||||
|
2. **Batch end marker**: `fswatch --batch-marker` emits a `NoOp` signal at the end of each batch
|
||||||
|
3. **File sync**: each changed file is transferred with `scp`, preserving the relative path under the destination directory
|
||||||
|
4. **Cache clear**: on each `NoOp` (end of batch), `composer front-cache-clear` is run on the remote
|
||||||
|
5. **Cleanup on exit**: Ctrl+C triggers `git reset --hard` and a final cache clear on the remote
|
||||||
|
|
||||||
|
## Default Configuration
|
||||||
|
|
||||||
|
Edit the three constants at the top of `dir-sync.sh` to set your own defaults:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
DEFAULT_LOCAL_PATH='/path/to/local/dir/'
|
||||||
|
DEFAULT_REMOTE_PATH='/path/to/remote/dir/'
|
||||||
|
DEFAULT_HOST='devac'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- [`fswatch`](https://github.com/emcrisostomo/fswatch) — file system watcher
|
||||||
|
- `scp` and `ssh` — standard OpenSSH tools
|
||||||
|
- A remote host configured in `~/.ssh/config` (password-less key auth recommended)
|
||||||
|
- `composer` available on the remote host (for cache clearing)
|
||||||
|
|
||||||
|
### Installing fswatch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# macOS
|
||||||
|
brew install fswatch
|
||||||
|
|
||||||
|
# Linux (Ubuntu/Debian)
|
||||||
|
sudo apt install fswatch
|
||||||
|
```
|
||||||
|
|
||||||
|
## About
|
||||||
|
|
||||||
|
**Author:** Julien Gautier ([jgautier.webdev@gmail.com](mailto:jgautier.webdev@gmail.com))
|
||||||
|
|
||||||
|
**Organization:** AdAstra
|
||||||
|
|
||||||
|
**Project:** adastra_scripts
|
||||||
Executable
+164
@@ -0,0 +1,164 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Author: Julien Gautier <jgautier.webdev@gmail.com>
|
||||||
|
# Organization: AdAstra
|
||||||
|
# Project: adastra_scripts
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
# Directory Sync Utility Script
|
||||||
|
#
|
||||||
|
# Watches a local directory for file changes and syncs them to a remote host
|
||||||
|
# via SCP in real time. On exit (Ctrl+C), resets the remote repository and
|
||||||
|
# clears the remote cache.
|
||||||
|
#
|
||||||
|
# Usage: ./dir-sync.sh [OPTIONS]
|
||||||
|
#
|
||||||
|
# Options:
|
||||||
|
# -s, --source <path> Local directory absolute path
|
||||||
|
# -d, --dest <path> Remote directory absolute path
|
||||||
|
# -r, --remote-host <h> Remote SSH host
|
||||||
|
# -h, --help Print this help
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# ./dir-sync.sh -s /var/www/myapp/ -d /var/www/myapp/ -r myserver
|
||||||
|
# ./dir-sync.sh -s ~/projects/app/ -d /srv/app/ -r devhost
|
||||||
|
#
|
||||||
|
# Requirements:
|
||||||
|
# fswatch, scp, ssh
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# --- Configuration -----------------------------------------------------------
|
||||||
|
DEFAULT_LOCAL_PATH='/path/to/local/dir/'
|
||||||
|
DEFAULT_REMOTE_PATH='/path/to/remote/dir/'
|
||||||
|
DEFAULT_HOST='devhost'
|
||||||
|
|
||||||
|
# --- Colors ------------------------------------------------------------------
|
||||||
|
NONE='\033[0m'
|
||||||
|
BOLD='\033[1m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[0;33m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
MAGENTA='\033[0;35m'
|
||||||
|
BBLUE='\033[1;94m'
|
||||||
|
|
||||||
|
# --- Usage -------------------------------------------------------------------
|
||||||
|
usage() {
|
||||||
|
echo -e "
|
||||||
|
${BOLD}NAME${NONE}
|
||||||
|
dir-sync — Synchronize a local folder to a remote host
|
||||||
|
|
||||||
|
${BOLD}SYNOPSIS${NONE}
|
||||||
|
bash $0 [OPTION]...
|
||||||
|
|
||||||
|
${BOLD}OPTIONS${NONE}
|
||||||
|
-h, --help Print this help
|
||||||
|
-s, --source <path> Local directory absolute path
|
||||||
|
-d, --dest <path> Remote directory absolute path
|
||||||
|
-r, --remote-host <h> Remote SSH host
|
||||||
|
|
||||||
|
${RED}Example:${NONE} $0 -s /path/to/local/ -d /path/to/remote/ -r sshhost
|
||||||
|
"
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Prerequisite checks -----------------------------------------------------
|
||||||
|
check_deps() {
|
||||||
|
local missing=0
|
||||||
|
for cmd in fswatch scp ssh; do
|
||||||
|
if ! command -v "$cmd" &>/dev/null; then
|
||||||
|
echo -e "${RED}✗ Missing required command: ${cmd}${NONE}"
|
||||||
|
missing=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[ "$missing" -eq 0 ] || exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Cleanup (runs on INT/TERM) ----------------------------------------------
|
||||||
|
cleanup() {
|
||||||
|
echo -e "\n${CYAN}♻️ Resetting remote repository...${NONE}"
|
||||||
|
echo -e "\$> ${MAGENTA}ssh ${host} \"cd '${dir_remote}'; git reset --hard\"${NONE}"
|
||||||
|
ssh "$host" "cd '${dir_remote}'; git reset --hard"
|
||||||
|
|
||||||
|
echo -e "\n${CYAN}🗑️ Clearing remote cache...${NONE}"
|
||||||
|
echo -e "\$> ${MAGENTA}ssh ${host} \"cd '${dir_remote}'; composer front-cache-clear\"${NONE}"
|
||||||
|
ssh "$host" "cd '${dir_remote}'; composer front-cache-clear"
|
||||||
|
|
||||||
|
wait
|
||||||
|
echo -e "\n${GREEN}✔ Done.${NONE}"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Sync a single file ------------------------------------------------------
|
||||||
|
sync_file() {
|
||||||
|
local local_path="$1"
|
||||||
|
local remote_path="${local_path/$dir_local/$dir_remote}"
|
||||||
|
echo -e "\n${CYAN}🔄 Syncing ${YELLOW}${local_path/$dir_local/}${NONE}"
|
||||||
|
echo -e "\$> ${MAGENTA}scp '${local_path}' ${host}:'${remote_path}'${NONE}"
|
||||||
|
scp "${local_path}" "${host}:${remote_path}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Main --------------------------------------------------------------------
|
||||||
|
clear
|
||||||
|
|
||||||
|
echo -e "${BBLUE}🔎 Starting $0${NONE}"
|
||||||
|
echo -e "${BLUE}-------------------------------${NONE}"
|
||||||
|
|
||||||
|
check_deps
|
||||||
|
|
||||||
|
dir_local=''
|
||||||
|
dir_remote=''
|
||||||
|
host=''
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help) usage; exit 0 ;;
|
||||||
|
-s|--source) dir_local="$2"; shift 2 ;;
|
||||||
|
-d|--dest) dir_remote="$2"; shift 2 ;;
|
||||||
|
-r|--remote-host) host="$2"; shift 2 ;;
|
||||||
|
*)
|
||||||
|
echo -e "${RED}✗ Unknown option: $1${NONE}"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "$dir_local" ]]; then
|
||||||
|
dir_local="$DEFAULT_LOCAL_PATH"
|
||||||
|
echo -e "${YELLOW}⚠ Local path: ${dir_local} (default)${NONE}"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}⚙️ Local path: ${dir_local}${NONE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$dir_remote" ]]; then
|
||||||
|
dir_remote="$DEFAULT_REMOTE_PATH"
|
||||||
|
echo -e "${YELLOW}⚠ Remote path: ${dir_remote} (default)${NONE}"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}⚙️ Remote path: ${dir_remote}${NONE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$host" ]]; then
|
||||||
|
host="$DEFAULT_HOST"
|
||||||
|
echo -e "${YELLOW}⚠ Remote host: ${host} (default)${NONE}"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}⚙️ Remote host: ${host}${NONE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap cleanup INT TERM
|
||||||
|
|
||||||
|
echo -e "\n${BBLUE}⏳ Watching for changes...${NONE}"
|
||||||
|
echo -e "${BLUE}-----------------------------${NONE}"
|
||||||
|
|
||||||
|
while IFS= read -r file; do
|
||||||
|
if [[ "$file" == "NoOp" ]]; then
|
||||||
|
echo -e "\n${CYAN}🗑️ Clearing remote cache...${NONE}"
|
||||||
|
echo -e "\$> ${MAGENTA}ssh ${host} \"cd '${dir_remote}'; composer front-cache-clear\"${NONE}"
|
||||||
|
ssh "$host" "cd '${dir_remote}'; composer front-cache-clear"
|
||||||
|
echo -e "\n${BBLUE}⏳ Watching for changes...${NONE}"
|
||||||
|
echo -e "${BLUE}-----------------------------${NONE}"
|
||||||
|
else
|
||||||
|
sync_file "$file" &
|
||||||
|
fi
|
||||||
|
done < <(fswatch --batch-marker -0 --exclude '.git/' "$dir_local" | tr '\0' '\n')
|
||||||
@@ -0,0 +1,500 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>MongoDB Dump Utility</title>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: #333;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
page-break-after: always;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
color: white;
|
||||||
|
padding: 50px 40px;
|
||||||
|
text-align: center;
|
||||||
|
page-break-after: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
header h1 {
|
||||||
|
font-size: 2.8em;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
header p {
|
||||||
|
font-size: 1.6em;
|
||||||
|
opacity: 0.95;
|
||||||
|
font-weight: 300;
|
||||||
|
color: #FFF;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-left: 4px solid #667eea;
|
||||||
|
padding: 30px 40px;
|
||||||
|
margin: 30px 0;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc h2 {
|
||||||
|
color: #667eea;
|
||||||
|
font-size: 1.3em;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc ul {
|
||||||
|
list-style: none;
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc li {
|
||||||
|
margin: 8px 0;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
border-bottom: 1px dotted #667eea;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a:hover {
|
||||||
|
color: #764ba2;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
padding: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
section {
|
||||||
|
margin-bottom: 40px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
color: #667eea;
|
||||||
|
font-size: 1.8em;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
margin-top: 30px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
border-bottom: 2px solid #667eea;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
color: #764ba2;
|
||||||
|
font-size: 1.3em;
|
||||||
|
margin: 20px 0 12px 0;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
text-align: justify;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul, ol {
|
||||||
|
margin-left: 25px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
strong {
|
||||||
|
color: #333;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 2px 6px;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.95em;
|
||||||
|
color: #d63384;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background-color: #2d2d2d;
|
||||||
|
color: #f8f8f2;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
overflow-x: auto;
|
||||||
|
margin: 15px 0;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
line-height: 1.4;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
border-left: 4px solid #667eea;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre code {
|
||||||
|
background-color: transparent;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
color: #f8f8f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note {
|
||||||
|
background-color: #e7f3ff;
|
||||||
|
border-left: 4px solid #2196F3;
|
||||||
|
padding: 15px 20px;
|
||||||
|
margin: 20px 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning {
|
||||||
|
background-color: #fff3cd;
|
||||||
|
border-left: 4px solid #ffc107;
|
||||||
|
padding: 15px 20px;
|
||||||
|
margin: 20px 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-structure {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border: 1px solid #dee2e6;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
line-height: 1.6;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
margin: 15px 0;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-top: 2px solid #667eea;
|
||||||
|
padding: 30px 40px;
|
||||||
|
margin-top: 40px;
|
||||||
|
text-align: center;
|
||||||
|
color: #666;
|
||||||
|
font-size: 0.95em;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer p {
|
||||||
|
margin: 8px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta {
|
||||||
|
color: #667eea;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: #764ba2;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<header>
|
||||||
|
<h1>MongoDB Dump Utility</h1>
|
||||||
|
<p>Database Server Backup Management</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="toc">
|
||||||
|
<h2>Table of Contents</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#quick-start">Quick Start</a></li>
|
||||||
|
<li><a href="#commands">Commands</a></li>
|
||||||
|
<li><a href="#how-it-works">How It Works</a></li>
|
||||||
|
<li><a href="#configuration">Configuration Files</a></li>
|
||||||
|
<li><a href="#directory">Directory Structure</a></li>
|
||||||
|
<li><a href="#output">Dump Output</a></li>
|
||||||
|
<li><a href="#accessing">Accessing Dumps</a></li>
|
||||||
|
<li><a href="#security">Security</a></li>
|
||||||
|
<li><a href="#requirements">Requirements</a></li>
|
||||||
|
<li><a href="#installation">Installation</a></li>
|
||||||
|
<li><a href="#troubleshooting">Troubleshooting</a></li>
|
||||||
|
<li><a href="#advanced">Advanced Usage</a></li>
|
||||||
|
<li><a href="#support">Support</a></li>
|
||||||
|
<li><a href="#about">About</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section>
|
||||||
|
<p style="font-style: italic; color: #777; margin-bottom: 20px;">
|
||||||
|
This directory contains a standalone tool for backing up MongoDB databases from remote or local servers. It manages multiple environment configurations for easy switching between prod, uat, and other environments.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="quick-start">
|
||||||
|
<h2>Quick Start</h2>
|
||||||
|
|
||||||
|
<h3>First Run</h3>
|
||||||
|
<pre><code>./db-dump.sh dump</code></pre>
|
||||||
|
|
||||||
|
<p>The script will detect no environments and guide you through creating one. Answer the prompts with:</p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Environment name</strong> (required): e.g., <code>prod</code>, <code>uat</code>, <code>staging</code></li>
|
||||||
|
<li><strong>MongoDB username</strong> (required): The admin user</li>
|
||||||
|
<li><strong>MongoDB password</strong> (required): The admin password</li>
|
||||||
|
<li><strong>MongoDB host</strong> (required): e.g., <code>cluster0.mongodb.net</code></li>
|
||||||
|
<li><strong>MongoDB port</strong> (required): Usually <code>27017</code> or <code>10255</code></li>
|
||||||
|
<li><strong>Application name</strong> (required): Used in connection string and dump folder name</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Subsequent Runs</h3>
|
||||||
|
<pre><code>./db-dump.sh dump</code></pre>
|
||||||
|
|
||||||
|
<p>The script will show you a list of configured environments and let you choose which one to backup, or create a new environment.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="commands">
|
||||||
|
<h2>Commands</h2>
|
||||||
|
<pre><code># Perform a backup of a selected environment
|
||||||
|
./db-dump.sh dump
|
||||||
|
|
||||||
|
# List all configured environments
|
||||||
|
./db-dump.sh list
|
||||||
|
|
||||||
|
# Add a new environment
|
||||||
|
./db-dump.sh add
|
||||||
|
|
||||||
|
# Delete an environment
|
||||||
|
./db-dump.sh delete
|
||||||
|
|
||||||
|
# Show help
|
||||||
|
./db-dump.sh help</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="how-it-works">
|
||||||
|
<h2>How It Works</h2>
|
||||||
|
<ol>
|
||||||
|
<li><strong>Environment Selection</strong>: On each run, you select from existing environments or create new ones</li>
|
||||||
|
<li><strong>Credential Storage</strong>: Each environment's credentials are stored in <code>.env.<name></code> files</li>
|
||||||
|
<li><strong>MongoDB Connection</strong>: Connects using your credentials with MongoDB Atlas parameters (ssl, replicaSet, etc.)</li>
|
||||||
|
<li><strong>Dump Creation</strong>: Uses <code>mongodump</code> to create a backup</li>
|
||||||
|
<li><strong>Timestamped Output</strong>: Dumps are organized as <code>./dumps/<appName>/<yyyymmdd_hhmm>/</code></li>
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="configuration">
|
||||||
|
<h2>Configuration Files</h2>
|
||||||
|
|
||||||
|
<p>Each environment is stored in a separate file:</p>
|
||||||
|
<pre><code>.env.prod # Production environment
|
||||||
|
.env.uat # UAT environment
|
||||||
|
.env.staging # Staging environment (if created)</code></pre>
|
||||||
|
|
||||||
|
<p>Each file contains:</p>
|
||||||
|
<pre><code>MONGO_USERNAME=<username>
|
||||||
|
MONGO_PASSWORD=<password>
|
||||||
|
MONGO_HOST=<host>
|
||||||
|
MONGO_PORT=<port>
|
||||||
|
APP_NAME=<appName></code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="directory">
|
||||||
|
<h2>Directory Structure</h2>
|
||||||
|
<div class="file-structure">dbdump/
|
||||||
|
├── db-dump.sh # Main script
|
||||||
|
├── .env.prod # Production config (created by user)
|
||||||
|
├── .env.uat # UAT config (created by user)
|
||||||
|
├── .env.example # Example configuration
|
||||||
|
├── .gitignore # Git ignore rules
|
||||||
|
├── README.md # This file
|
||||||
|
└── dumps/ # Created automatically
|
||||||
|
├── prod/
|
||||||
|
│ ├── 20260414_1632/
|
||||||
|
│ │ ├── admin/
|
||||||
|
│ │ └── myapp/
|
||||||
|
│ └── 20260414_1645/
|
||||||
|
└── uat/
|
||||||
|
└── 20260414_1632/</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="output">
|
||||||
|
<h2>Dump Output</h2>
|
||||||
|
|
||||||
|
<p>Dumps are stored with the following structure:</p>
|
||||||
|
<pre><code>dumps/<appName>/<yyyymmdd_hhmi>/
|
||||||
|
admin/ # System databases
|
||||||
|
config/
|
||||||
|
myapp/ # Application databases
|
||||||
|
system.profile/</code></pre>
|
||||||
|
|
||||||
|
<p>Each backup preserves the complete database structure and is ready to be restored using <code>mongorestore</code>.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="accessing">
|
||||||
|
<h2>Accessing Dumps</h2>
|
||||||
|
|
||||||
|
<p>To view or restore a dump:</p>
|
||||||
|
<pre><code># List recent dumps
|
||||||
|
ls -lh dumps/prod/
|
||||||
|
|
||||||
|
# Restore a dump to local MongoDB
|
||||||
|
mongorestore --uri "mongodb://localhost:27017" dumps/prod/20260414_1632/
|
||||||
|
|
||||||
|
# Copy dump to another location
|
||||||
|
cp -r dumps/prod/20260414_1632/ /backup/prod-backup-20260414/</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="security">
|
||||||
|
<h2>Security</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Configuration files have restricted permissions (600)</li>
|
||||||
|
<li>Credentials are stored locally in <code>.env.*</code> files</li>
|
||||||
|
<li>These files are git-ignored for security</li>
|
||||||
|
<li>Never commit <code>.env.*</code> files to version control</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="requirements">
|
||||||
|
<h2>Requirements</h2>
|
||||||
|
<ul>
|
||||||
|
<li><strong>MongoDB Database Tools</strong>: Download from <a href="https://www.mongodb.com/try/download/database-tools">https://www.mongodb.com/try/download/database-tools</a>
|
||||||
|
<ul>
|
||||||
|
<li>Specifically requires <code>mongodump</code> command</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>Bash shell</li>
|
||||||
|
<li>Network access to MongoDB server</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="installation">
|
||||||
|
<h2>Installation of MongoDB Database Tools</h2>
|
||||||
|
|
||||||
|
<h3>macOS</h3>
|
||||||
|
<pre><code>brew tap mongodb/brew
|
||||||
|
brew install mongodb-database-tools</code></pre>
|
||||||
|
|
||||||
|
<h3>Linux (Ubuntu/Debian)</h3>
|
||||||
|
<pre><code>wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-x86_64-100.8.0.tgz
|
||||||
|
tar -xzf mongodb-database-tools-ubuntu2004-x86_64-100.8.0.tgz
|
||||||
|
sudo cp mongodb-database-tools-ubuntu2004-x86_64-100.8.0/bin/* /usr/local/bin/</code></pre>
|
||||||
|
|
||||||
|
<h3>Windows</h3>
|
||||||
|
<p>Download the MSI installer from <a href="https://www.mongodb.com/try/download/database-tools">https://www.mongodb.com/try/download/database-tools</a> and run it.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="troubleshooting">
|
||||||
|
<h2>Troubleshooting</h2>
|
||||||
|
|
||||||
|
<h3>mongodump not found</h3>
|
||||||
|
<pre><code># Check if MongoDB Database Tools is installed
|
||||||
|
mongodump --version
|
||||||
|
|
||||||
|
# If not installed, see "Installation" section above</code></pre>
|
||||||
|
|
||||||
|
<h3>Connection refused</h3>
|
||||||
|
<ul>
|
||||||
|
<li>Verify host and port are correct</li>
|
||||||
|
<li>Check network connectivity to MongoDB server</li>
|
||||||
|
<li>Ensure firewall allows access</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Authentication failed</h3>
|
||||||
|
<ul>
|
||||||
|
<li>Verify username and password</li>
|
||||||
|
<li>Check the user has admin permissions</li>
|
||||||
|
<li>Confirm the <code>authSource=admin</code> parameter</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Port already displaying in error</h3>
|
||||||
|
<p>The connection string is checked for errors. If you see connection errors, the script displays the exact MongoDB error message.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="advanced">
|
||||||
|
<h2>Advanced Usage</h2>
|
||||||
|
|
||||||
|
<h3>Manual mongodump command (for reference)</h3>
|
||||||
|
|
||||||
|
<p>The script constructs and runs this command automatically:</p>
|
||||||
|
<pre><code>mongodump --uri "mongodb://<username>:<password>@<host>:<port>/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@<appName>@" -o ./dumps/<appName>/<yyyymmdd_hhmm></code></pre>
|
||||||
|
|
||||||
|
<h3>Scheduling automated backups</h3>
|
||||||
|
<p>You can schedule regular backups using cron (Linux/macOS):</p>
|
||||||
|
<pre><code># Add to crontab
|
||||||
|
crontab -e
|
||||||
|
|
||||||
|
# Daily dump at 3 AM for production environment
|
||||||
|
0 3 * * * cd /path/to/dbdump && ./db-dump.sh dump << EOF
|
||||||
|
1
|
||||||
|
EOF</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="support">
|
||||||
|
<h2>Support</h2>
|
||||||
|
|
||||||
|
<p>For MongoDB connection issues, refer to:</p>
|
||||||
|
<ul>
|
||||||
|
<li>MongoDB Documentation: <a href="https://docs.mongodb.com/">https://docs.mongodb.com/</a></li>
|
||||||
|
<li>Connection String Reference: <a href="https://docs.mongodb.com/manual/reference/connection-string/">https://docs.mongodb.com/manual/reference/connection-string/</a></li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="about">
|
||||||
|
<h2>About</h2>
|
||||||
|
<p>
|
||||||
|
<strong>Author:</strong> Julien Gautier (<a href="mailto:jgautier.webdev@gmail.com">jgautier.webdev@gmail.com</a>)
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Organization:</strong> AdAstra
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Project:</strong> adastra_scripts
|
||||||
|
</p>
|
||||||
|
<p style="margin-top: 20px; color: #999;">
|
||||||
|
This utility was created to enable efficient backup and versioning of MongoDB databases from remote or local servers for AdAstra projects.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<p>MongoDB Dump Utility Documentation</p>
|
||||||
|
<p>Generated with care for <span class="meta">AdAstra</span> projects</p>
|
||||||
|
<p style="margin-top: 15px; font-size: 0.9em; border-top: 1px solid #ddd; padding-top: 15px;">
|
||||||
|
© 2026 AdAstra - All rights reserved
|
||||||
|
</p>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,546 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>MongoDB Restore Utility</title>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: #333;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
page-break-after: always;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
color: white;
|
||||||
|
padding: 50px 40px;
|
||||||
|
text-align: center;
|
||||||
|
page-break-after: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
header h1 {
|
||||||
|
font-size: 2.8em;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
header p {
|
||||||
|
font-size: 1.6em;
|
||||||
|
opacity: 0.95;
|
||||||
|
font-weight: 300;
|
||||||
|
color: #FFF;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-left: 4px solid #667eea;
|
||||||
|
padding: 30px 40px;
|
||||||
|
margin: 30px 0;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc h2 {
|
||||||
|
color: #667eea;
|
||||||
|
font-size: 1.3em;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc ul {
|
||||||
|
list-style: none;
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc li {
|
||||||
|
margin: 8px 0;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
border-bottom: 1px dotted #667eea;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a:hover {
|
||||||
|
color: #764ba2;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
padding: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
section {
|
||||||
|
margin-bottom: 40px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
color: #667eea;
|
||||||
|
font-size: 1.8em;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
margin-top: 30px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
border-bottom: 2px solid #667eea;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
color: #764ba2;
|
||||||
|
font-size: 1.3em;
|
||||||
|
margin: 20px 0 12px 0;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
text-align: justify;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul, ol {
|
||||||
|
margin-left: 25px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
strong {
|
||||||
|
color: #333;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 2px 6px;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.95em;
|
||||||
|
color: #d63384;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background-color: #2d2d2d;
|
||||||
|
color: #f8f8f2;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
overflow-x: auto;
|
||||||
|
margin: 15px 0;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
line-height: 1.4;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
border-left: 4px solid #667eea;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre code {
|
||||||
|
background-color: transparent;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
color: #f8f8f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note {
|
||||||
|
background-color: #e7f3ff;
|
||||||
|
border-left: 4px solid #2196F3;
|
||||||
|
padding: 15px 20px;
|
||||||
|
margin: 20px 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning {
|
||||||
|
background-color: #fff3cd;
|
||||||
|
border-left: 4px solid #ffc107;
|
||||||
|
padding: 15px 20px;
|
||||||
|
margin: 20px 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-structure {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border: 1px solid #dee2e6;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
line-height: 1.6;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
margin: 15px 0;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-top: 2px solid #667eea;
|
||||||
|
padding: 30px 40px;
|
||||||
|
margin-top: 40px;
|
||||||
|
text-align: center;
|
||||||
|
color: #666;
|
||||||
|
font-size: 0.95em;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer p {
|
||||||
|
margin: 8px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta {
|
||||||
|
color: #667eea;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: #764ba2;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<header>
|
||||||
|
<h1>MongoDB Restore Utility</h1>
|
||||||
|
<p>Standalone Backup Restoration Tool</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="toc">
|
||||||
|
<h2>Table of Contents</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#quick-start">Quick Start</a></li>
|
||||||
|
<li><a href="#how-it-works">How It Works</a></li>
|
||||||
|
<li><a href="#interactive">Interactive Navigation</a></li>
|
||||||
|
<li><a href="#backup-detection">Backup Detection</a></li>
|
||||||
|
<li><a href="#example">Example Use Case</a></li>
|
||||||
|
<li><a href="#summary">Restore Summary</a></li>
|
||||||
|
<li><a href="#connection">Connection String</a></li>
|
||||||
|
<li><a href="#directory">Directory Structure</a></li>
|
||||||
|
<li><a href="#security">Security</a></li>
|
||||||
|
<li><a href="#requirements">Requirements</a></li>
|
||||||
|
<li><a href="#installation">Installation</a></li>
|
||||||
|
<li><a href="#troubleshooting">Troubleshooting</a></li>
|
||||||
|
<li><a href="#manual">Manual Restore Command</a></li>
|
||||||
|
<li><a href="#related">Related Tools</a></li>
|
||||||
|
<li><a href="#workflow">Workflow Example</a></li>
|
||||||
|
<li><a href="#about">About</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section>
|
||||||
|
<p style="font-style: italic; color: #777; margin-bottom: 20px;">
|
||||||
|
This directory contains a standalone tool for restoring MongoDB database backups created with <code>db-dump.sh</code>. It provides interactive navigation through backup directories and restores them to a configured MongoDB instance.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="quick-start">
|
||||||
|
<h2>Quick Start</h2>
|
||||||
|
|
||||||
|
<h3>1. Configure Connection Details</h3>
|
||||||
|
<pre><code>cp .env.example .env</code></pre>
|
||||||
|
|
||||||
|
<p>Edit <code>.env</code> with your MongoDB connection details:</p>
|
||||||
|
<pre><code>MONGO_USERNAME=admin
|
||||||
|
MONGO_PASSWORD=password
|
||||||
|
MONGO_HOST=localhost
|
||||||
|
MONGO_PORT=27017
|
||||||
|
MONGO_DATABASE=adastradb
|
||||||
|
MONGO_AUTHSOURCE=admin</code></pre>
|
||||||
|
|
||||||
|
<h3>2. Restore a Backup</h3>
|
||||||
|
<pre><code>./db-restore.sh</code></pre>
|
||||||
|
|
||||||
|
<p>The script will:</p>
|
||||||
|
<ol>
|
||||||
|
<li>Verify MongoDB tools are installed</li>
|
||||||
|
<li>Load your configuration</li>
|
||||||
|
<li>Ask for the path to your backups directory</li>
|
||||||
|
<li>Guide you through the directory structure</li>
|
||||||
|
<li>Show a summary of what will be restored</li>
|
||||||
|
<li>Ask for confirmation</li>
|
||||||
|
<li>Restore the backup</li>
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="how-it-works">
|
||||||
|
<h2>How It Works</h2>
|
||||||
|
|
||||||
|
<h3>Configuration</h3>
|
||||||
|
|
||||||
|
<p>The script requires a <code>.env</code> file with these variables:</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>MONGO_USERNAME</code> - MongoDB admin username</li>
|
||||||
|
<li><code>MONGO_PASSWORD</code> - MongoDB admin password</li>
|
||||||
|
<li><code>MONGO_HOST</code> - MongoDB server hostname/IP</li>
|
||||||
|
<li><code>MONGO_PORT</code> - MongoDB server port</li>
|
||||||
|
<li><code>MONGO_DATABASE</code> - Target database name</li>
|
||||||
|
<li><code>MONGO_AUTHSOURCE</code> - Authentication source (usually <code>admin</code>)</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="interactive">
|
||||||
|
<h2>Interactive Navigation</h2>
|
||||||
|
|
||||||
|
<p>The script intelligently navigates through your backup directory structure:</p>
|
||||||
|
<div class="file-structure">dumps/
|
||||||
|
├── prod/ - Choose this
|
||||||
|
│ ├── 20260414_1632/ - Then this
|
||||||
|
│ │ └── (database folders) - Then this
|
||||||
|
│ └── 20260414_1645/
|
||||||
|
└── uat/
|
||||||
|
└── 20260414_1700/</div>
|
||||||
|
|
||||||
|
<p>At each level, the script:</p>
|
||||||
|
<ol>
|
||||||
|
<li>Shows available subdirectories</li>
|
||||||
|
<li>Asks you to choose one</li>
|
||||||
|
<li>Continues until it finds <code>.bson</code> files (backup data)</li>
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="backup-detection">
|
||||||
|
<h2>Backup Detection</h2>
|
||||||
|
|
||||||
|
<p>The script automatically stops navigation when it finds a directory containing <code>.bson</code> files, which are the actual backup data files.</p>
|
||||||
|
|
||||||
|
<p>Example backup structure:</p>
|
||||||
|
<pre><code>~/Works/dbdump/dumps/
|
||||||
|
└── bo-uat-cosmodb/
|
||||||
|
└── 20260414_1732/
|
||||||
|
└── admin/ - BSON files here
|
||||||
|
├── system.profile.bson
|
||||||
|
└── system.version.bson</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="example">
|
||||||
|
<h2>Example Use Case</h2>
|
||||||
|
|
||||||
|
<p>Given this backup structure:</p>
|
||||||
|
<pre><code>~/Works/dbdump/dumps/
|
||||||
|
├── bo-prod-cosmodb/
|
||||||
|
│ └── 20260414_1600/
|
||||||
|
│ └── AdAstra/
|
||||||
|
│ ├── collection1.bson
|
||||||
|
│ └── collection1.metadata.json
|
||||||
|
└── bo-uat-cosmodb/
|
||||||
|
└── 20260414_1732/
|
||||||
|
└── AdAstra/
|
||||||
|
├── orders.bson
|
||||||
|
└── orders.metadata.json</code></pre>
|
||||||
|
|
||||||
|
<p>Restore process:</p>
|
||||||
|
<pre><code>./db-restore.sh
|
||||||
|
|
||||||
|
# Script asks: Dumps path: ~/Works/dbdump/dumps
|
||||||
|
# Shows: 1) bo-prod-cosmodb 2) bo-uat-cosmodb
|
||||||
|
# You choose: 2
|
||||||
|
# Shows: 1) 20260414_1732
|
||||||
|
# You choose: 1
|
||||||
|
# Shows: 1) AdAstra
|
||||||
|
# You choose: 1
|
||||||
|
# Script finds BSON files and shows summary</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="summary">
|
||||||
|
<h2>Restore Summary</h2>
|
||||||
|
|
||||||
|
<p>Before executing the restore, the script displays:</p>
|
||||||
|
<pre><code>MongoDB Connection:
|
||||||
|
Host: localhost
|
||||||
|
Port: 27017
|
||||||
|
Username: admin
|
||||||
|
Database: adastradb
|
||||||
|
AuthSource: admin
|
||||||
|
|
||||||
|
Backup Source:
|
||||||
|
Location: /home/user/Works/dbdump/dumps/bo-uat-cosmodb/20260414_1732
|
||||||
|
Backup files: 42
|
||||||
|
Total size: 250M</code></pre>
|
||||||
|
|
||||||
|
<p>You must confirm with "yes" to proceed.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="connection">
|
||||||
|
<h2>Connection String</h2>
|
||||||
|
|
||||||
|
<p>The script constructs the MongoDB connection string as:</p>
|
||||||
|
<pre><code>mongodb://<username>:<password>@<host>:<port>/<database>?authSource=<authSource></code></pre>
|
||||||
|
|
||||||
|
<p>Example:</p>
|
||||||
|
<pre><code>mongodb://admin:password@localhost:27017/adastradb?authSource=admin</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="directory">
|
||||||
|
<h2>Directory Structure</h2>
|
||||||
|
<div class="file-structure">dbrestore/
|
||||||
|
├── db-restore.sh # Main script
|
||||||
|
├── .env # Configuration (created by you, git-ignored)
|
||||||
|
├── .env.example # Example configuration
|
||||||
|
├── .gitignore # Git ignore rules
|
||||||
|
└── README.md # This file</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="security">
|
||||||
|
<h2>Security</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Configuration file (<code>.env</code>) has restricted permissions</li>
|
||||||
|
<li>Contains sensitive credentials (username, password)</li>
|
||||||
|
<li>Never commit actual <code>.env</code> file to version control</li>
|
||||||
|
<li>Use <code>.env.example</code> as template</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="requirements">
|
||||||
|
<h2>Requirements</h2>
|
||||||
|
<ul>
|
||||||
|
<li><strong>MongoDB Database Tools</strong>: Download from <a href="https://www.mongodb.com/try/download/database-tools">https://www.mongodb.com/try/download/database-tools</a>
|
||||||
|
<ul>
|
||||||
|
<li>Specifically requires <code>mongorestore</code> command</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li>Bash shell</li>
|
||||||
|
<li>Network access to MongoDB server</li>
|
||||||
|
<li>Backup files created by <code>db-dump.sh</code> or <code>mongodump</code></li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="installation">
|
||||||
|
<h2>Installation of MongoDB Database Tools</h2>
|
||||||
|
|
||||||
|
<h3>macOS</h3>
|
||||||
|
<pre><code>brew tap mongodb/brew
|
||||||
|
brew install mongodb-database-tools</code></pre>
|
||||||
|
|
||||||
|
<h3>Linux (Ubuntu/Debian)</h3>
|
||||||
|
<pre><code>wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-x86_64-100.8.0.tgz
|
||||||
|
tar -xzf mongodb-database-tools-ubuntu2004-x86_64-100.8.0.tgz
|
||||||
|
sudo cp mongodb-database-tools-ubuntu2004-x86_64-100.8.0/bin/* /usr/local/bin/</code></pre>
|
||||||
|
|
||||||
|
<h3>Windows</h3>
|
||||||
|
<p>Download the MSI installer from <a href="https://www.mongodb.com/try/download/database-tools">https://www.mongodb.com/try/download/database-tools</a> and run it.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="troubleshooting">
|
||||||
|
<h2>Troubleshooting</h2>
|
||||||
|
|
||||||
|
<h3>mongorestore not found</h3>
|
||||||
|
<pre><code># Check if MongoDB Database Tools is installed
|
||||||
|
mongorestore --version
|
||||||
|
|
||||||
|
# If not installed, see "Installation" section above</code></pre>
|
||||||
|
|
||||||
|
<h3>.env file not found</h3>
|
||||||
|
<pre><code># Copy the example configuration
|
||||||
|
cp .env.example .env
|
||||||
|
|
||||||
|
# Edit with your values
|
||||||
|
nano .env # or your favorite editor</code></pre>
|
||||||
|
|
||||||
|
<h3>Connection refused</h3>
|
||||||
|
<ul>
|
||||||
|
<li>Verify host and port are correct</li>
|
||||||
|
<li>Check network connectivity to MongoDB server</li>
|
||||||
|
<li>Ensure firewall allows access</li>
|
||||||
|
<li>Verify MongoDB service is running (if local)</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Authentication failed</h3>
|
||||||
|
<ul>
|
||||||
|
<li>Verify username and password in <code>.env</code></li>
|
||||||
|
<li>Check user has sufficient permissions</li>
|
||||||
|
<li>Confirm <code>authSource</code> is correct (usually <code>admin</code>)</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>No BSON files found</h3>
|
||||||
|
<ul>
|
||||||
|
<li>Make sure you're pointing to the root of dumps directory</li>
|
||||||
|
<li>Navigate through subdirectories until you reach the folder with actual backup files</li>
|
||||||
|
<li>BSON files are typically deep in the directory structure</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="manual">
|
||||||
|
<h2>Manual Restore Command</h2>
|
||||||
|
|
||||||
|
<p>For reference, here's the command the script executes:</p>
|
||||||
|
<pre><code>mongorestore --uri "mongodb://user:pass@host:port/db?authSource=admin" /path/to/dumps</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="related">
|
||||||
|
<h2>Related Tools</h2>
|
||||||
|
<ul>
|
||||||
|
<li><strong>dbutils/db-start.sh</strong> - Start MongoDB in Docker for restoring locally</li>
|
||||||
|
<li><strong>dbdump/db-dump.sh</strong> - Create backups from remote MongoDB servers</li>
|
||||||
|
<li><strong>dbrestore/db-restore.sh</strong> - Restore backups to a MongoDB instance (this tool)</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="workflow">
|
||||||
|
<h2>Workflow Example</h2>
|
||||||
|
|
||||||
|
<p>Complete workflow to backup and restore:</p>
|
||||||
|
<pre><code># 1. Backup from production MongoDB (in dbdump folder)
|
||||||
|
cd ~/Works/dbdump
|
||||||
|
./db-dump.sh dump
|
||||||
|
# Select prod environment and wait for backup</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="about">
|
||||||
|
<h2>About</h2>
|
||||||
|
<p>
|
||||||
|
<strong>Author:</strong> Julien Gautier (<a href="mailto:jgautier.webdev@gmail.com">jgautier.webdev@gmail.com</a>)
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Organization:</strong> AdAstra
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Project:</strong> adastra_scripts
|
||||||
|
</p>
|
||||||
|
<p style="margin-top: 20px; color: #999;">
|
||||||
|
These utilities were created to simplify MongoDB management during local development of AdAstra projects.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<p>MongoDB Restore Utility Documentation</p>
|
||||||
|
<p>Generated with care for <span class="meta">AdAstra</span> projects</p>
|
||||||
|
<p style="margin-top: 15px; font-size: 0.9em; border-top: 1px solid #ddd; padding-top: 15px;">
|
||||||
|
© 2026 AdAstra - All rights reserved
|
||||||
|
</p>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,513 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>MongoDB Database Utility (Standalone)</title>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: #333;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
page-break-after: always;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
color: white;
|
||||||
|
padding: 50px 40px;
|
||||||
|
text-align: center;
|
||||||
|
page-break-after: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
header h1 {
|
||||||
|
font-size: 2.8em;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
header p {
|
||||||
|
font-size: 1.6em;
|
||||||
|
opacity: 0.95;
|
||||||
|
font-weight: 300;
|
||||||
|
color: #FFF;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-left: 4px solid #667eea;
|
||||||
|
padding: 30px 40px;
|
||||||
|
margin: 30px 0;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc h2 {
|
||||||
|
color: #667eea;
|
||||||
|
font-size: 1.3em;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc ul {
|
||||||
|
list-style: none;
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc li {
|
||||||
|
margin: 8px 0;
|
||||||
|
font-size: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
border-bottom: 1px dotted #667eea;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc a:hover {
|
||||||
|
color: #764ba2;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
padding: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
section {
|
||||||
|
margin-bottom: 40px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
color: #667eea;
|
||||||
|
font-size: 1.8em;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
margin-top: 30px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
border-bottom: 2px solid #667eea;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
color: #764ba2;
|
||||||
|
font-size: 1.3em;
|
||||||
|
margin: 20px 0 12px 0;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
text-align: justify;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul, ol {
|
||||||
|
margin-left: 25px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
strong {
|
||||||
|
color: #333;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 2px 6px;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.95em;
|
||||||
|
color: #d63384;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background-color: #2d2d2d;
|
||||||
|
color: #f8f8f2;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 5px;
|
||||||
|
overflow-x: auto;
|
||||||
|
margin: 15px 0;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
line-height: 1.4;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
border-left: 4px solid #667eea;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre code {
|
||||||
|
background-color: transparent;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
color: #f8f8f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight {
|
||||||
|
background-color: #fff3cd;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note {
|
||||||
|
background-color: #e7f3ff;
|
||||||
|
border-left: 4px solid #2196F3;
|
||||||
|
padding: 15px 20px;
|
||||||
|
margin: 20px 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning {
|
||||||
|
background-color: #fff3cd;
|
||||||
|
border-left: 4px solid #ffc107;
|
||||||
|
padding: 15px 20px;
|
||||||
|
margin: 20px 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.danger {
|
||||||
|
background-color: #f8d7da;
|
||||||
|
border-left: 4px solid #dc3545;
|
||||||
|
padding: 15px 20px;
|
||||||
|
margin: 20px 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-structure {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border: 1px solid #dee2e6;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
line-height: 1.6;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
margin: 15px 0;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin: 20px 0;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color: #667eea;
|
||||||
|
color: white;
|
||||||
|
padding: 12px;
|
||||||
|
text-align: left;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
padding: 12px;
|
||||||
|
border-bottom: 1px solid #dee2e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even) {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:hover {
|
||||||
|
background-color: #e7f3ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-top: 2px solid #667eea;
|
||||||
|
padding: 30px 40px;
|
||||||
|
margin-top: 40px;
|
||||||
|
text-align: center;
|
||||||
|
color: #666;
|
||||||
|
font-size: 0.95em;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer p {
|
||||||
|
margin: 8px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta {
|
||||||
|
color: #667eea;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color: #764ba2;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.command {
|
||||||
|
display: inline-block;
|
||||||
|
background-color: #e7f3ff;
|
||||||
|
border: 1px solid #667eea;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
font-family: 'Courier New', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: #0066cc;
|
||||||
|
margin: 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title-page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
min-height: 100vh;
|
||||||
|
page-break-after: always;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-break {
|
||||||
|
page-break-after: always;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<header>
|
||||||
|
<h1>MongoDB Database Utility</h1>
|
||||||
|
<p>Standalone Local Development Setup</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="toc">
|
||||||
|
<h2>Table of Contents</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#quick-start">Quick Start</a></li>
|
||||||
|
<li><a href="#commands">Common Commands</a></li>
|
||||||
|
<li><a href="#accessing">Accessing MongoDB</a></li>
|
||||||
|
<li><a href="#persistence">Data Persistence</a></li>
|
||||||
|
<li><a href="#collections">Collections</a></li>
|
||||||
|
<li><a href="#structure">File Structure</a></li>
|
||||||
|
<li><a href="#configuration">Configuration</a></li>
|
||||||
|
<li><a href="#requirements">Requirements</a></li>
|
||||||
|
<li><a href="#standalone">Standalone Usage</a></li>
|
||||||
|
<li><a href="#troubleshooting">Troubleshooting</a></li>
|
||||||
|
<li><a href="#notes">Notes</a></li>
|
||||||
|
<li><a href="#about">About</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<section>
|
||||||
|
<p style="font-style: italic; color: #777; margin-bottom: 20px;">
|
||||||
|
This directory contains a standalone MongoDB setup for local development. It is completely independent from the main backend and frontend projects.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="quick-start">
|
||||||
|
<h2>Quick Start</h2>
|
||||||
|
|
||||||
|
<h3>First Run (Setup)</h3>
|
||||||
|
<pre><code>./db-start.sh up</code></pre>
|
||||||
|
|
||||||
|
<p>The script will prompt you for:</p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>MongoDB username</strong> (default: <code>admin</code>)</li>
|
||||||
|
<li><strong>MongoDB password</strong> (default: <code>password</code>)</li>
|
||||||
|
<li><strong>Database name</strong> (default: <code>adastradb</code>)</li>
|
||||||
|
<li><strong>MongoDB port</strong> (default: <code>27017</code>)</li>
|
||||||
|
<li><strong>Mongo Express port</strong> (default: <code>8081</code>)</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Your configuration will be stored in <code>.env</code> file (automatically git-ignored).</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="commands">
|
||||||
|
<h2>Common Commands</h2>
|
||||||
|
<pre><code># Start MongoDB (prompts for credentials on first run)
|
||||||
|
./db-start.sh up
|
||||||
|
|
||||||
|
# View logs
|
||||||
|
./db-start.sh logs
|
||||||
|
|
||||||
|
# Stop MongoDB
|
||||||
|
./db-start.sh down
|
||||||
|
|
||||||
|
# Restart MongoDB
|
||||||
|
./db-start.sh restart
|
||||||
|
|
||||||
|
# Check container status
|
||||||
|
./db-start.sh status
|
||||||
|
|
||||||
|
# Reconfigure credentials
|
||||||
|
./db-start.sh reconfigure
|
||||||
|
|
||||||
|
# Remove all containers and volumes (DATA LOSS!)
|
||||||
|
./db-start.sh clean
|
||||||
|
|
||||||
|
# Show help
|
||||||
|
./db-start.sh help</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="accessing">
|
||||||
|
<h2>Accessing MongoDB</h2>
|
||||||
|
|
||||||
|
<h3>From Your Application</h3>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Connection String:</strong> <code>mongodb://<username>:<password>@localhost:27017/<database>?authSource=admin</code></li>
|
||||||
|
<li><strong>Example:</strong> <code>mongodb://admin:password@localhost:27017/adastradb?authSource=admin</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Using Mongo Express (GUI)</h3>
|
||||||
|
<ul>
|
||||||
|
<li><strong>URL:</strong> <a href="http://localhost:8081">http://localhost:8081</a></li>
|
||||||
|
<li><strong>Username:</strong> <code>dev</code></li>
|
||||||
|
<li><strong>Password:</strong> <code>dev</code></li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="persistence">
|
||||||
|
<h2>Data Persistence</h2>
|
||||||
|
<p>All data is stored in Docker volumes and persists across container restarts. To permanently delete data, use:</p>
|
||||||
|
<pre><code>./db-start.sh clean</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="collections">
|
||||||
|
<h2>Collections</h2>
|
||||||
|
<p>The database is automatically initialized with the following collection:</p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>dataImportHistory:</strong> Stores records of all data imports for audit and recovery tracking
|
||||||
|
<ul>
|
||||||
|
<li>Indexed on <code>importDate</code> (descending) and <code>status</code></li>
|
||||||
|
<li>Ready for future data import functionality</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="structure">
|
||||||
|
<h2>File Structure</h2>
|
||||||
|
<div class="file-structure">dbutils/
|
||||||
|
├── db-start.sh # Main script
|
||||||
|
├── docker-compose-mongodb.yml # Docker Compose configuration
|
||||||
|
├── mongo-init.js # Database initialization script
|
||||||
|
├── .env # Configuration (generated on first run, git-ignored)
|
||||||
|
├── .env.example # Example configuration
|
||||||
|
├── .gitignore # Git ignore rules
|
||||||
|
└── README.md # This file</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="configuration">
|
||||||
|
<h2>Configuration</h2>
|
||||||
|
<p>The script uses a <code>.env</code> file to store configuration. You can:</p>
|
||||||
|
<ol>
|
||||||
|
<li><strong>Let the script generate it:</strong> Run <code>./db-start.sh up</code> and answer the prompts</li>
|
||||||
|
<li><strong>Pre-create it:</strong> Copy <code>.env.example</code> to <code>.env</code> and modify values</li>
|
||||||
|
<li><strong>Edit it manually:</strong> Edit <code>.env</code> directly and run <code>./db-start.sh up</code></li>
|
||||||
|
<li><strong>Reconfigure:</strong> Run <code>./db-start.sh reconfigure</code> to re-run the setup wizard</li>
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="requirements">
|
||||||
|
<h2>Requirements</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Docker</li>
|
||||||
|
<li>Docker Compose (included with Docker Desktop)</li>
|
||||||
|
<li>Bash shell</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="standalone">
|
||||||
|
<h2>Standalone Usage</h2>
|
||||||
|
<p>This utility can be used independently from AdAstra projects:</p>
|
||||||
|
<pre><code># From anywhere
|
||||||
|
cd /path/to/dbutils
|
||||||
|
./db-start.sh up
|
||||||
|
|
||||||
|
# Or add to PATH and use globally (optional)
|
||||||
|
export PATH=$PATH:/path/to/dbutils
|
||||||
|
db-start.sh up</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="troubleshooting">
|
||||||
|
<h2>Troubleshooting</h2>
|
||||||
|
|
||||||
|
<h3>Port already in use</h3>
|
||||||
|
<p>If MongoDB or Mongo Express port is already in use:</p>
|
||||||
|
<ol>
|
||||||
|
<li>Run <code>./db-start.sh reconfigure</code></li>
|
||||||
|
<li>Choose a different port (e.g., 27018 for MongoDB, 8082 for Mongo Express)</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<h3>Docker not running</h3>
|
||||||
|
<pre><code># Check Docker status
|
||||||
|
docker info</code></pre>
|
||||||
|
|
||||||
|
<h3>Permission denied</h3>
|
||||||
|
<pre><code># Make script executable
|
||||||
|
chmod +x db-start.sh</code></pre>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="notes">
|
||||||
|
<h2>Notes</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Credentials are stored in <code>.env</code> (git-ignored for security)</li>
|
||||||
|
<li>Mongo Express is included for easy database management</li>
|
||||||
|
<li>Data persists in Docker volumes</li>
|
||||||
|
<li>No initialization scripts are run (unlike the backend docker-compose)</li>
|
||||||
|
<li>This is standalone and independent from the main project configuration</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="about">
|
||||||
|
<h2>About</h2>
|
||||||
|
<p>
|
||||||
|
<strong>Author:</strong> Julien Gautier (<a href="mailto:jgautier.webdev@gmail.com">jgautier.webdev@gmail.com</a>)
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Organization:</strong> AdAstra
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>Project:</strong> adastra_scripts
|
||||||
|
</p>
|
||||||
|
<p style="margin-top: 20px; color: #999;">
|
||||||
|
These utilities were created to simplify MongoDB management during local development of AdAstra projects.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<p>MongoDB Database Utility Documentation</p>
|
||||||
|
<p>Generated with care for <span class="meta">AdAstra</span> projects</p>
|
||||||
|
<p style="margin-top: 15px; font-size: 0.9em; border-top: 1px solid #ddd; padding-top: 15px;">
|
||||||
|
© 2026 AdAstra - All rights reserved
|
||||||
|
</p>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user