Auto-discover active Pangolin directory from Docker inspect and backup Docker volumes

This commit is contained in:
jschantli committed 2026-09-04 20:35:00 -07:00
1 parent f74a3e09f5
commit 5c44884c5c
2 files changed
+70 -13

No files matched your search

+41 -7
View File
@@ -87,17 +87,51 @@ async def run_backup_task(
remote_commands = [
f'echo "=== STEP 1: Creating Hot-Snapshot on Remote VPS ({vps_host}) ==="',
f'mkdir -p "{remote_stage}/pangolin"',
f'echo "--- Staging Pangolin files from {p_dir} ---"',
f'if [ -d "{p_dir}" ]; then rsync -av --exclude="*.db" --exclude="*.db-wal" --exclude="*.db-shm" "{p_dir}/" "{remote_stage}/pangolin/"; fi',
f'echo "--- Performing zero-lock hot-backup of SQLite databases on VPS ---"',
f"""
for db in $(find "{p_dir}" -name "*.db" -o -name "*.sqlite" 2>/dev/null); do
rel=$(realpath --relative-to="{p_dir}" "$db")
f'''
P_DIR="{p_dir}"
if [ ! -d "$P_DIR" ] || [ -z "$(ls -A "$P_DIR" 2>/dev/null)" ]; then
echo "Notice: Configured path $P_DIR is empty or does not exist."
echo "Searching VPS for Pangolin Docker compose stack..."
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" ] && [ -n "$(ls -A "$DETECTED" 2>/dev/null)" ]; then
echo "--> Auto-discovered active Pangolin directory at: $DETECTED"
P_DIR="$DETECTED"
else
echo "--> Warning: Could not locate alternate Pangolin directory. Staging from $P_DIR"
fi
fi
echo "--- Staging Pangolin files from $P_DIR ---"
if [ -d "$P_DIR" ]; then
rsync -av --exclude="*.db" --exclude="*.db-wal" --exclude="*.db-shm" "$P_DIR/" "{remote_stage}/pangolin/"
fi
echo "--- Performing zero-lock hot-backup of SQLite databases on VPS ---"
for db in $(find "$P_DIR" -name "*.db" -o -name "*.sqlite" 2>/dev/null); do
rel=$(realpath --relative-to="$P_DIR" "$db")
mkdir -p "{remote_stage}/pangolin/$(dirname "$rel")"
echo "Hot-backing up $rel..."
sqlite3 "$db" ".backup '{remote_stage}/pangolin/$rel'" 2>/dev/null || cp -v "$db" "{remote_stage}/pangolin/$rel"
done
"""
# Backup any named Docker volumes attached to pangolin containers
for vol in $(docker inspect --format '{{{{range .Mounts}}}}{{{{if eq .Type "volume"}}}}{{{{.Source}}}}{{{{"\\n"}}}}{{{{end}}}}{{{{end}}}}' $(docker ps -aq --filter "name=pangolin" 2>/dev/null) 2>/dev/null); do
if [ -d "$vol" ] && [ -n "$(ls -A "$vol" 2>/dev/null)" ]; then
vname=$(basename "$vol")
echo "--- Staging Docker Volume: $vname from $vol ---"
mkdir -p "{remote_stage}/pangolin/volumes/$vname"
cp -a "$vol/." "{remote_stage}/pangolin/volumes/$vname/" 2>/dev/null || true
fi
done
'''
]
if scope in ["vps_config", "full"]: