refactor: convert repository to monorepo with npm workspaces
Restructured the repository into a monorepo to better organize application code and maintenance scripts. ## Workspace Structure - web-app: Next.js application (all app code moved from root) - housekeeping: Database backup and maintenance scripts ## Key Changes - Moved all application code to web-app/ using git mv - Moved database scripts to housekeeping/ workspace - Updated Dockerfile for monorepo build process - Updated docker-compose files (volume paths: ./web-app/etc/hosts/) - Updated .gitignore for workspace-level node_modules - Updated documentation (README.md, CLAUDE.md, CHANGELOG.md) ## Migration Impact - Root package.json now manages workspaces - Build commands delegate to web-app workspace - All file history preserved via git mv - Docker build process updated for workspace structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
70
housekeeping/db-backup--swarm.sh
Executable file
70
housekeeping/db-backup--swarm.sh
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# ==============================================================================
|
||||
# MongoDB Offline Volume Backup Script (Docker Swarm)
|
||||
# ==============================================================================
|
||||
#
|
||||
# PURPOSE:
|
||||
# Creates an offline backup of the complete mongo-volume directory.
|
||||
# The MongoDB service is scaled down during the backup to ensure consistency.
|
||||
#
|
||||
# WHEN TO USE:
|
||||
# - For Docker Swarm deployments (not standalone Docker)
|
||||
# - When you need a complete volume backup (entire MongoDB data directory)
|
||||
# - For disaster recovery scenarios
|
||||
# - When consistency is critical and downtime is acceptable
|
||||
#
|
||||
# BACKUP TYPE:
|
||||
# - Offline (cold) backup - DB service is scaled to 0 during backup
|
||||
# - Volume-level backup - entire mongo-volume directory
|
||||
# - Creates compressed tarball (.tar.gz) of the volume
|
||||
#
|
||||
# OUTPUT:
|
||||
# - Backup files stored in: ./mongo-backup/
|
||||
# - Filename format: mongo-volume-backup-YYYY-MM-DD-HH-MM.tar.gz
|
||||
# - Automatic rotation: keeps newest 7 backups (configurable via KEEP env var)
|
||||
#
|
||||
# USAGE:
|
||||
# ./db-backup--swarm.sh
|
||||
# KEEP=10 ./db-backup--swarm.sh # Keep 10 backups instead of 7
|
||||
#
|
||||
# NOTE:
|
||||
# The MongoDB service will be scaled down to 0 and then back up to 1.
|
||||
# Expect brief downtime during the backup process.
|
||||
#
|
||||
# ==============================================================================
|
||||
|
||||
# Configuration
|
||||
MONGO_SERVICE="utility-bills-tracker_mongo"
|
||||
|
||||
# scale down mongo service while we copy its volume
|
||||
docker service scale "$MONGO_SERVICE"=0
|
||||
|
||||
# timestamp for filename
|
||||
TIMESTAMP=$(date +"%Y-%m-%d-%H-%M")
|
||||
|
||||
# backup directory and retention (can be overridden via env)
|
||||
BACKUP_DIR="${BACKUP_DIR:-mongo-backup}"
|
||||
KEEP="${KEEP:-7}"
|
||||
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
BACKUP_FILE="$BACKUP_DIR/mongo-volume-backup-$TIMESTAMP.tar.gz"
|
||||
|
||||
sudo tar -czvpf "$BACKUP_FILE" mongo-volume
|
||||
|
||||
# rotate old backups: keep only the newest $KEEP files
|
||||
if [ "$KEEP" -gt 0 ]; then
|
||||
# gather files sorted newest-first
|
||||
mapfile -t files < <(ls -1t "$BACKUP_DIR"/mongo-volume-backup-*.tar.gz 2>/dev/null || true)
|
||||
if [ "${#files[@]}" -gt "$KEEP" ]; then
|
||||
for f in "${files[@]:$KEEP}"; do
|
||||
echo "Removing old backup: $f"
|
||||
rm -f -- "$f"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# bring mongo service back up
|
||||
docker service scale "$MONGO_SERVICE"=1
|
||||
Reference in New Issue
Block a user