Files
evidencija-rezija/db-backup-swarm.sh
Knee Cola 5832e9e691 Refactor deployment scripts to separate standalone and swarm modes
- Remove ambiguous docker-compose-deploy.yml and debug-deploy.sh
- Update deploy-standalone.sh to use docker-compose-standalone.yaml
- Update deploy-swarm.sh to use docker-compose-swarm.yml
- Standardize error messages to English in deployment scripts
- Add db-backup-swarm.sh for swarm-specific backups
- Unify network naming to util-bills-mongo-network across configs
- Fix MongoDB credentials in swarm compose file

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:28:16 +01:00

37 lines
942 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# 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:-backups}"
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