backup/restore: use MONGO_SERVICE variable for service name

This commit is contained in:
2025-08-24 08:29:01 +00:00
parent 64496b8cd8
commit 9c29838092
2 changed files with 10 additions and 4 deletions

View File

@@ -1,8 +1,11 @@
#!/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 utility-bills-tracker_mongo=0
docker service scale "$MONGO_SERVICE"=0
# timestamp for filename
TIMESTAMP=$(date +"%Y-%m-%d-%H-%M")
@@ -30,4 +33,4 @@ if [ "$KEEP" -gt 0 ]; then
fi
# bring mongo service back up
docker service scale utility-bills-tracker_mongo=1
docker service scale "$MONGO_SERVICE"=1

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
# Configuration
MONGO_SERVICE="utility-bills-tracker_mongo"
# Usage: ./restore.sh <timestamp>
# Example: ./restore.sh 2025-08-24-14-30
@@ -37,7 +40,7 @@ fi
# Scale down mongo service
echo "Scaling down mongo service..."
docker service scale utility-bills-tracker_mongo=0
docker service scale "$MONGO_SERVICE"=0
# Backup current volume (just in case)
SAFETY_BACKUP="mongo-volume-pre-restore-$(date +%Y-%m-%d-%H-%M).tar.gz"
@@ -58,7 +61,7 @@ sudo chown -R 999:999 mongo-volume
# Scale mongo service back up
echo "Scaling mongo service back up..."
docker service scale utility-bills-tracker_mongo=1
docker service scale "$MONGO_SERVICE"=1
echo "Restore completed successfully!"
echo "Safety backup saved as: $SAFETY_BACKUP"