File size: 1,376 Bytes
503b0e9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #!/usr/bin/env bash
set -euo pipefail
# Idempotently set up host-namespaced data/logs under dbops/b/<host_id>
# and symlink stable paths `data` and `logs` to them.
DBOPS_ROOT=${DBOPS_ROOT:-/data/adaptai/platform/dbops}
HOST_ID=${HOST_ID:-$(hostname -s 2>/dev/null || echo host)}
echo "[hostns] DBOPS_ROOT=$DBOPS_ROOT HOST_ID=$HOST_ID"
mkdir -p "$DBOPS_ROOT/b/$HOST_ID/data" "$DBOPS_ROOT/b/$HOST_ID/logs"
# Move current dirs into host namespace if not symlinks
backup_sfx=$(date +%s)
if [ ! -L "$DBOPS_ROOT/data" ] && [ -d "$DBOPS_ROOT/data" ]; then
echo "[hostns] migrating data/ -> b/$HOST_ID/data"
rsync -a "$DBOPS_ROOT/data/" "$DBOPS_ROOT/b/$HOST_ID/data/" || true
mv "$DBOPS_ROOT/data" "$DBOPS_ROOT/data.bak.$backup_sfx" || true
fi
if [ ! -L "$DBOPS_ROOT/logs" ] && [ -d "$DBOPS_ROOT/logs" ]; then
echo "[hostns] migrating logs/ -> b/$HOST_ID/logs"
rsync -a "$DBOPS_ROOT/logs/" "$DBOPS_ROOT/b/$HOST_ID/logs/" || true
mv "$DBOPS_ROOT/logs" "$DBOPS_ROOT/logs.bak.$backup_sfx" || true
fi
ln -sfn "$DBOPS_ROOT/b/$HOST_ID/data" "$DBOPS_ROOT/data"
ln -sfn "$DBOPS_ROOT/b/$HOST_ID/logs" "$DBOPS_ROOT/logs"
# Ensure common service subdirs exist
for svc in dragonfly janusgraph qdrant redis scylla; do
mkdir -p "$DBOPS_ROOT/data/$svc"
mkdir -p "$DBOPS_ROOT/logs/$svc"
done
echo "[hostns] complete:"
ls -l "$DBOPS_ROOT" | egrep ' data$| logs$' || true
exit 0
|