Auto-discover active Pangolin directory from Docker inspect and backup Docker volumes
This commit is contained in:
1 parent
f74a3e09f5
commit
5c44884c5c
2 files changed
+70
-13
No files matched your search
+29
-6
@@ -31,11 +31,28 @@ async def get_pangolin_stack_status() -> Dict[str, Any]:
|
||||
|
||||
# Query Remote VPS for files, DB, and Docker status
|
||||
check_script = f"""
|
||||
[ -f "{p_dir}/docker-compose.yml" ] || [ -f "{p_dir}/compose.yaml" ] && echo "COMPOSE_EXISTS" || echo "COMPOSE_NO"
|
||||
[ -f "{p_dir}/config/config.yml" ] || [ -f "{p_dir}/config.yml" ] && echo "CONFIG_EXISTS" || echo "CONFIG_NO"
|
||||
P_DIR="{p_dir}"
|
||||
if [ ! -d "$P_DIR" ] || [ -z "$(ls -A "$P_DIR" 2>/dev/null)" ]; then
|
||||
DETECTED=$(docker inspect --format '{{{{index .Config.Labels \"com.docker.compose.project.working_dir\"}}}}' $(docker ps -aq --filter "name=pangolin" 2>/dev/null) 2>/dev/null | head -n 1)
|
||||
if [ -z "$DETECTED" ] || [ ! -d "$DETECTED" ]; then
|
||||
for candidate in /root/pangolin /opt/pangolin /home/*/pangolin /var/lib/pangolin /srv/pangolin /etc/pangolin; do
|
||||
if [ -d "$candidate" ] && [ -n "$(ls -A "$candidate" 2>/dev/null)" ]; then
|
||||
DETECTED="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [ -n "$DETECTED" ] && [ -d "$DETECTED" ]; then
|
||||
P_DIR="$DETECTED"
|
||||
fi
|
||||
fi
|
||||
echo "RESOLVED_DIR:$P_DIR"
|
||||
|
||||
[ -f "$P_DIR/docker-compose.yml" ] || [ -f "$P_DIR/compose.yaml" ] && echo "COMPOSE_EXISTS" || echo "COMPOSE_NO"
|
||||
[ -f "$P_DIR/config/config.yml" ] || [ -f "$P_DIR/config.yml" ] && echo "CONFIG_EXISTS" || echo "CONFIG_NO"
|
||||
|
||||
# Check DB
|
||||
db=$(find "{p_dir}" -name "*.db" -o -name "*.sqlite" 2>/dev/null | head -n 1)
|
||||
db=$(find "$P_DIR" -name "*.db" -o -name "*.sqlite" 2>/dev/null | head -n 1)
|
||||
if [ -n "$db" ]; then
|
||||
echo "DB_PATH:$db"
|
||||
wc -c "$db" 2>/dev/null | awk '{{print $1}}'
|
||||
@@ -45,7 +62,7 @@ else
|
||||
fi
|
||||
|
||||
# Docker containers
|
||||
docker ps -a --format '{{json .}}' 2>/dev/null || true
|
||||
docker ps -a --format '{{{{json .}}}}' 2>/dev/null || true
|
||||
"""
|
||||
ret, stdout, stderr = await run_remote_quick(check_script, settings)
|
||||
|
||||
@@ -54,7 +71,7 @@ docker ps -a --format '{{json .}}' 2>/dev/null || true
|
||||
"vps_configured": True,
|
||||
"connected": False,
|
||||
"installed": False,
|
||||
"path": p_dir,
|
||||
"path": resolved_path,
|
||||
"compose_exists": False,
|
||||
"config_exists": False,
|
||||
"database": {"found": False, "path": None, "size_bytes": 0},
|
||||
@@ -66,6 +83,12 @@ docker ps -a --format '{{json .}}' 2>/dev/null || true
|
||||
}
|
||||
|
||||
lines = stdout.splitlines()
|
||||
resolved_path = p_dir
|
||||
for l in lines:
|
||||
if l.startswith("RESOLVED_DIR:"):
|
||||
resolved_path = l.split(":", 1)[1].strip()
|
||||
break
|
||||
|
||||
compose_exists = any("COMPOSE_EXISTS" in l for l in lines)
|
||||
config_exists = any("CONFIG_EXISTS" in l for l in lines)
|
||||
|
||||
@@ -107,7 +130,7 @@ docker ps -a --format '{{json .}}' 2>/dev/null || true
|
||||
"vps_configured": True,
|
||||
"connected": True,
|
||||
"installed": compose_exists,
|
||||
"path": p_dir,
|
||||
"path": resolved_path,
|
||||
"compose_exists": compose_exists,
|
||||
"config_exists": config_exists,
|
||||
"database": {
|
||||
|
||||
Reference in new issue
Block a user