134 lines
4.2 KiB
Bash
134 lines
4.2 KiB
Bash
#!/bin/bash
|
|
set -x
|
|
|
|
# ==========================================================
|
|
# VERIFY BACKUP INTEGRITY
|
|
# Kontroluje že se indexy, metadata, a všechny kolekce
|
|
# správně obnovily
|
|
# ==========================================================
|
|
|
|
CONTAINER_NAME="MongoDB"
|
|
MONGO_HOST="localhost"
|
|
MONGO_PORT="27017"
|
|
|
|
# Databases to verify
|
|
WHAT_TO_VERIFY=("admin" "fio" "torrents" "OrdinaceDropBoxBackup" "medevio" "kanboard" "medicus" "studie" "puzzle")
|
|
|
|
echo "Starting backup integrity verification..."
|
|
echo "=========================================="
|
|
|
|
ALL_OK=true
|
|
|
|
for DB_NAME in "${WHAT_TO_VERIFY[@]}"; do
|
|
echo ""
|
|
echo "Verifying database: $DB_NAME"
|
|
echo "------------------------------------------"
|
|
|
|
# ======================================================
|
|
# 1. CHECK IF DB EXISTS
|
|
# ======================================================
|
|
DB_EXISTS=$(docker exec "$CONTAINER_NAME" mongosh \
|
|
--host="$MONGO_HOST" \
|
|
--port="$MONGO_PORT" \
|
|
--quiet \
|
|
--eval "db.adminCommand('listDatabases').databases.filter(d => d.name === '$DB_NAME').length > 0")
|
|
|
|
if [ "$DB_EXISTS" != "true" ]; then
|
|
echo "❌ ERROR: Database $DB_NAME does not exist!"
|
|
ALL_OK=false
|
|
continue
|
|
fi
|
|
echo "✅ Database exists: $DB_NAME"
|
|
|
|
# ======================================================
|
|
# 2. COUNT COLLECTIONS
|
|
# ======================================================
|
|
COLLECTION_COUNT=$(docker exec "$CONTAINER_NAME" mongosh \
|
|
--host="$MONGO_HOST" \
|
|
--port="$MONGO_PORT" \
|
|
--quiet \
|
|
--eval "use $DB_NAME; db.getCollectionNames().length")
|
|
|
|
echo "✅ Collections count: $COLLECTION_COUNT"
|
|
|
|
# ======================================================
|
|
# 3. LIST ALL COLLECTIONS
|
|
# ======================================================
|
|
echo " Collections:"
|
|
docker exec "$CONTAINER_NAME" mongosh \
|
|
--host="$MONGO_HOST" \
|
|
--port="$MONGO_PORT" \
|
|
--quiet \
|
|
--eval "use $DB_NAME; db.getCollectionNames().forEach(c => print(' - ' + c))"
|
|
|
|
# ======================================================
|
|
# 4. CHECK INDEXES FOR EACH COLLECTION
|
|
# ======================================================
|
|
echo " Indexes per collection:"
|
|
docker exec "$CONTAINER_NAME" mongosh \
|
|
--host="$MONGO_HOST" \
|
|
--port="$MONGO_PORT" \
|
|
--quiet \
|
|
--eval "
|
|
use $DB_NAME;
|
|
db.getCollectionNames().forEach(collName => {
|
|
const indexes = db[collName].getIndexes();
|
|
print(' ' + collName + ': ' + indexes.length + ' indexes');
|
|
indexes.forEach(idx => {
|
|
print(' - ' + JSON.stringify(idx.key));
|
|
});
|
|
});
|
|
"
|
|
|
|
# ======================================================
|
|
# 5. CHECK COLLECTION STATS (document count, size)
|
|
# ======================================================
|
|
echo " Collection stats:"
|
|
docker exec "$CONTAINER_NAME" mongosh \
|
|
--host="$MONGO_HOST" \
|
|
--port="$MONGO_PORT" \
|
|
--quiet \
|
|
--eval "
|
|
use $DB_NAME;
|
|
db.getCollectionNames().forEach(collName => {
|
|
const stats = db[collName].stats();
|
|
print(' ' + collName + ':');
|
|
print(' Documents: ' + stats.count);
|
|
print(' Size: ' + (stats.size / 1024 / 1024).toFixed(2) + ' MB');
|
|
});
|
|
"
|
|
|
|
# ======================================================
|
|
# 6. VERIFY USERS/ROLES (if admin DB)
|
|
# ======================================================
|
|
if [ "$DB_NAME" = "admin" ]; then
|
|
echo " Users and Roles:"
|
|
USER_COUNT=$(docker exec "$CONTAINER_NAME" mongosh \
|
|
--host="$MONGO_HOST" \
|
|
--port="$MONGO_PORT" \
|
|
--quiet \
|
|
--eval "use admin; db.system.users.find().count()")
|
|
|
|
echo " System users: $USER_COUNT"
|
|
|
|
ROLE_COUNT=$(docker exec "$CONTAINER_NAME" mongosh \
|
|
--host="$MONGO_HOST" \
|
|
--port="$MONGO_PORT" \
|
|
--quiet \
|
|
--eval "use admin; db.system.roles.find().count()")
|
|
|
|
echo " System roles: $ROLE_COUNT"
|
|
fi
|
|
|
|
done
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
if [ "$ALL_OK" = true ]; then
|
|
echo "✅ All verifications passed!"
|
|
else
|
|
echo "❌ Some verifications failed!"
|
|
exit 1
|
|
fi
|
|
set +x
|