poc2_worked
This commit is contained in:
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "Docker Engine is required" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
IMAGE="${IDS_MIGRATION_IMAGE:-routeros-suricata-tzsp:local}"
|
||||
TARGET_VOLUME="${IDS_DATA_VOLUME:-routeros-suricata-data}"
|
||||
|
||||
docker volume create "$TARGET_VOLUME" >/dev/null
|
||||
|
||||
target_is_empty() {
|
||||
subpath="$1"
|
||||
docker run --rm --entrypoint /bin/sh \
|
||||
-v "${TARGET_VOLUME}:/target" \
|
||||
"$IMAGE" \
|
||||
-c "test ! -d '/target/${subpath}' || test -z \"\$(find '/target/${subpath}' -mindepth 1 -maxdepth 1 -print -quit 2>/dev/null)\""
|
||||
}
|
||||
|
||||
copy_host_dir() {
|
||||
source_dir="$1"
|
||||
target_subpath="$2"
|
||||
label="$3"
|
||||
|
||||
if [ ! -d "$source_dir" ] || [ -z "$(find "$source_dir" -mindepth 1 -maxdepth 1 -print -quit 2>/dev/null)" ]; then
|
||||
echo "[volume-migration] no legacy ${label} data in ${source_dir}; skipping"
|
||||
return 0
|
||||
fi
|
||||
if ! target_is_empty "$target_subpath"; then
|
||||
echo "[volume-migration] /data/${target_subpath} is not empty; leaving it unchanged"
|
||||
return 0
|
||||
fi
|
||||
|
||||
source_abs="$(cd "$source_dir" && pwd)"
|
||||
docker run --rm --entrypoint /bin/sh \
|
||||
-v "${source_abs}:/legacy:ro" \
|
||||
-v "${TARGET_VOLUME}:/target" \
|
||||
"$IMAGE" \
|
||||
-c "set -eu; mkdir -p '/target/${target_subpath}'; cp -a /legacy/. '/target/${target_subpath}/'"
|
||||
echo "[volume-migration] migrated ${label}: ${source_dir} -> ${TARGET_VOLUME}:/${target_subpath}"
|
||||
}
|
||||
|
||||
copy_named_volume() {
|
||||
source_volume="$1"
|
||||
target_subpath="$2"
|
||||
label="$3"
|
||||
|
||||
if ! docker volume inspect "$source_volume" >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
if ! target_is_empty "$target_subpath"; then
|
||||
echo "[volume-migration] /data/${target_subpath} is not empty; leaving legacy ${source_volume} unchanged"
|
||||
return 0
|
||||
fi
|
||||
|
||||
docker run --rm --entrypoint /bin/sh \
|
||||
-v "${source_volume}:/legacy:ro" \
|
||||
-v "${TARGET_VOLUME}:/target" \
|
||||
"$IMAGE" \
|
||||
-c "set -eu; if [ -n \"\$(find /legacy -mindepth 1 -maxdepth 1 -print -quit 2>/dev/null)\" ]; then mkdir -p '/target/${target_subpath}'; cp -a /legacy/. '/target/${target_subpath}/'; fi"
|
||||
echo "[volume-migration] merged ${label}: ${source_volume} -> ${TARGET_VOLUME}:/${target_subpath}"
|
||||
}
|
||||
|
||||
# <=0.6.1 host bind directories. Application data stays at /data root to
|
||||
# preserve ids.db and redis paths; logs/rules are folded into subdirectories.
|
||||
if target_is_empty ""; then
|
||||
copy_host_dir "data" "" "SQLite/Redis/application"
|
||||
else
|
||||
echo "[volume-migration] ${TARGET_VOLUME} already contains application data; keeping it"
|
||||
fi
|
||||
copy_host_dir "logs" "logs/suricata" "Suricata logs"
|
||||
copy_host_dir "data/vendor-rules" "lib/suricata" "vendor rules"
|
||||
|
||||
# 0.7.0 used three named volumes. Merge the two auxiliary volumes into the
|
||||
# single data volume without overwriting newer files.
|
||||
copy_named_volume "routeros-suricata-logs" "logs/suricata" "Suricata logs"
|
||||
copy_named_volume "routeros-suricata-rules" "lib/suricata" "Suricata rule state"
|
||||
Reference in New Issue
Block a user