Index: /branches/amp_3_7_2/scripts/import_es_snapshot.sh
===================================================================
--- /branches/amp_3_7_2/scripts/import_es_snapshot.sh	(revision 2852)
+++ /branches/amp_3_7_2/scripts/import_es_snapshot.sh	(working copy)
@@ -25,10 +25,20 @@
 LOG_FILE="/var/log/es_import.log"
 TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
 LOCAL_SNAPSHOT_DIR="/var/backups/es_snapshots"
+IMPORT_DIR="${LOCAL_SNAPSHOT_DIR}/import_${TIMESTAMP}"
+REPO_NAME="amp_restore_repo_${TIMESTAMP}"
 
+SSH_OPTS="-o StrictHostKeyChecking=no"
+
 log() { echo "$(date '+%F %T') $1" | tee -a "$LOG_FILE"; }
 fail() { log "ERROR: $1"; exit 1; }
 
+# ============================================================
+# START LOG
+# ============================================================
+log "==============================================="
+log " STARTING ELASTICSEARCH SNAPSHOT IMPORT "
+
 # -----------------------------------------------
 # Parse CLI arguments
 # -----------------------------------------------
\ No newline at end of file
@@ -56,9 +66,9 @@
 
 log "Restoring snapshot from remote AMP directory: $DIR"
 
-# -----------------------------------------------
-# STEP 1 — Detection snapshot name on remote AMP
-# -----------------------------------------------
+# ----------------------------------------------------------
+# STEP 1 — Detect snapshot name on remote AMP
+# ----------------------------------------------------------
 log "[1/9] Detecting snapshot name on source AMP..."
 
 # Using -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa to fix "incorrect signature" issues
\ No newline at end of file
@@ -79,27 +89,24 @@
 log "Snapshot detected: $SNAP_NAME"
 
 # ----------------------------------------------------------
-# STEP 2 — Clean local snapshot directory
+# STEP 2 — Create snapshot import directory
 # ----------------------------------------------------------
-log "[2/9] Cleaning local snapshot directory..."
+log "[2/9] Creating snapshot import directory..."
 
-if [[ -z "${LOCAL_SNAPSHOT_DIR:-}" || "$LOCAL_SNAPSHOT_DIR" == "/" ]]; then
-    fail "LOCAL_SNAPSHOT_DIR is invalid. Aborting to prevent system damage."
-fi
+mkdir -p "$IMPORT_DIR" || fail "Failed to create import directory"
+chown -R elasticsearch:elasticsearch "$IMPORT_DIR"
+chmod -R 755 "$IMPORT_DIR"
 
-rm -rf "${LOCAL_SNAPSHOT_DIR:?}/"* 2>>"$LOG_FILE" || fail "Failed to clean local snapshot directory"
-mkdir -p "$LOCAL_SNAPSHOT_DIR"
-chown -R elasticsearch:elasticsearch "$LOCAL_SNAPSHOT_DIR"
-chmod -R 755 "$LOCAL_SNAPSHOT_DIR"
+log "Using snapshot import directory: $IMPORT_DIR"
 
-# -----------------------------------------------
+# ----------------------------------------------------------
 # STEP 3 — Copy snapshot directory from remote AMP
-# -----------------------------------------------
+# ----------------------------------------------------------
 log "[3/9] Copying snapshot directory..."
 
 RSYNC_OUTPUT=$(sshpass -p "$AMP_PASS" rsync -avz \
     -e "ssh $SSH_OPTS" \
-    "$AMP_USER@$AMP_IP:$DIR/" "$LOCAL_SNAPSHOT_DIR/" 2>&1)
+    "$AMP_USER@$AMP_IP:$DIR/" "$IMPORT_DIR/" 2>&1)
 
 RSYNC_RET=$?
 echo "$RSYNC_OUTPUT" >> "$LOG_FILE"
\ No newline at end of file
@@ -108,30 +115,24 @@
     log "Snapshot directory copied successfully (rsync)"
 else
     log "ERROR: rsync failed. Attempting fallback to SCP..."
-    echo "Rsync Output: $RSYNC_OUTPUT"
 
-    # FALLBACK TO SCP
-    # recursive copy of contents
     SCP_OUTPUT=$(sshpass -p "$AMP_PASS" scp -r $SSH_OPTS \
-        "$AMP_USER@$AMP_IP:$DIR/"* "$LOCAL_SNAPSHOT_DIR/" 2>&1)
-        
+        "$AMP_USER@$AMP_IP:$DIR/"* "$IMPORT_DIR/" 2>&1)
+
     SCP_RET=$?
     echo "$SCP_OUTPUT" >> "$LOG_FILE"
 
     if [ $SCP_RET -eq 0 ]; then
-            log "Snapshot directory copied successfully (scp)"
+        log "Snapshot directory copied successfully (scp)"
     else
-            log "ERROR: SCP fallback failed"
-            echo "SCP Output: $SCP_OUTPUT"
-            fail "Remote copy failed (rsync and scp)"
+        fail "Remote copy failed (rsync and scp)"
     fi
 fi
 
-log "Fixing snapshot directory ownership after rsync..."
+log "Fixing snapshot directory ownership..."
+chown -R elasticsearch:elasticsearch "$IMPORT_DIR"
+chmod -R 755 "$IMPORT_DIR"
 
-chown -R elasticsearch:elasticsearch "$LOCAL_SNAPSHOT_DIR"
-chmod -R 755 "$LOCAL_SNAPSHOT_DIR"
-
 # ----------------------------------------------------------
 # STEP 4 — Set path.repo and restart Elasticsearch
 # ----------------------------------------------------------
\ No newline at end of file
@@ -151,14 +152,14 @@
 systemctl restart elasticsearch >> "$LOG_FILE" 2>&1 || fail "Elasticsearch restart failed"
 sleep 5
 
-# -----------------------------------------------
-# STEP 5 — Register ES repository
-# -----------------------------------------------
-log "[5/9] Registering snapshot repository in Elasticsearch"
+# ----------------------------------------------------------
+# STEP 5 — Register snapshot repository
+# ----------------------------------------------------------
+log "[5/9] Registering snapshot repository..."
 
-REPO_RESPONSE=$(curl -s -XPUT "http://localhost:9200/_snapshot/amp_restore_repo" \
-  -H "Content-Type: application/json" \
-  -d "{\"type\":\"fs\",\"settings\":{\"location\":\"$LOCAL_SNAPSHOT_DIR\"}}")
+REPO_RESPONSE=$(curl -s -XPUT "http://localhost:9200/_snapshot/$REPO_NAME" \
+    -H "Content-Type: application/json" \
+    -d "{\"type\":\"fs\",\"settings\":{\"location\":\"$IMPORT_DIR\"}}")
 
 echo "$REPO_RESPONSE" >> "$LOG_FILE"
 
\ No newline at end of file
@@ -187,7 +188,7 @@
 # -----------------------------------------------
 log "[6/9] Extracting index list..."
 
-curl -s "http://localhost:9200/_snapshot/amp_restore_repo/$SNAP_NAME" \
+curl -s "http://localhost:9200/_snapshot/$REPO_NAME/$SNAP_NAME" \
   | sed -n 's/.*"indices":\[\(.*\)\].*/\1/p' \
   | tr ',' '\n' | tr -d '"' > "$TMP_LIST"
 
\ No newline at end of file
@@ -221,7 +222,7 @@
 
         log "Restoring index: $INDEX"
 
-        RESTORE_RESPONSE=$(curl -s -XPOST "http://localhost:9200/_snapshot/amp_restore_repo/$SNAP_NAME/_restore" \
+        RESTORE_RESPONSE=$(curl -s -XPOST "http://localhost:9200/_snapshot/$REPO_NAME/$SNAP_NAME/_restore" \
           -H "Content-Type: application/json" \
           -d "{
                 \"indices\": \"$INDEX\",
\ No newline at end of file
@@ -230,7 +231,7 @@
                 \"rename_pattern\": \"(.+)\",
                 \"rename_replacement\": \"\$1_restored_${TIMESTAMP}\"
               }")
-        
+
         echo "$RESTORE_RESPONSE" >> "$LOG_FILE"
 
         if echo "$RESTORE_RESPONSE" | grep -qi '\"error\"'; then
\ No newline at end of file
@@ -251,21 +252,22 @@
 # -----------------------------------------------
 log "[8/9] FULL RESTORE PASS 1 — acm_*"
 
-RESTORE_P1=$(curl -s -XPOST "http://localhost:9200/_snapshot/amp_restore_repo/$SNAP_NAME/_restore" \
-  -H "Content-Type: application/json" \
-  -d "{
-        \"indices\": \"acm_*\",
-        \"ignore_unavailable\": true,
-        \"include_global_state\": false,
-        \"rename_pattern\": \"(.+)\",
-        \"rename_replacement\": \"\$1_restored_${TIMESTAMP}\"
-      }")
+RESTORE_P1=$(curl -s -X POST "http://localhost:9200/_snapshot/$REPO_NAME/$SNAP_NAME/_restore" \
+     -H "Content-Type: application/json" \
+     -d '{
+           "indices": "acm_*",
+           "ignore_unavailable": true,
+           "include_global_state": false,
+           "rename_pattern": "^acm_(.+)$",
+           "rename_replacement": "acm_new_'$TIMESTAMP'_$1"
+         }')
 
 echo "$RESTORE_P1" >> "$LOG_FILE"
+
 if echo "$RESTORE_P1" | grep -qi '\"error\"'; then
     log "ERROR: Full restore pass 1 failed"
-    echo "Elasticsearch Response: $RESTORE_P1"
-    fail "Restore pass 1 failed"
+    echo "Elasticsearch Response: RESTORE_P1"
+    fail "Restore PASS 1 failed"
 fi
 
 sleep 5
\ No newline at end of file
@@ -275,22 +277,27 @@
 # -----------------------------------------------
 log "[9/9] FULL RESTORE PASS 2 — non-acm"
 
-RESTORE_P2=$(curl -s -XPOST "http://localhost:9200/_snapshot/amp_restore_repo/$SNAP_NAME/_restore" \
-  -H "Content-Type: application/json" \
-  -d "{
-        \"indices\": \"*,-acm_*\",
-        \"ignore_unavailable\": true,
-        \"include_global_state\": false,
-        \"rename_pattern\": \"(.+)\",
-        \"rename_replacement\": \"\$1_restored_${TIMESTAMP}\"
-      }")
+RESTORE_P2=$(curl -s -X POST "http://localhost:9200/_snapshot/$REPO_NAME/$SNAP_NAME/_restore" \
+     -H "Content-Type: application/json" \
+     -d '{
+           "indices": "-acm_*",
+           "ignore_unavailable": true,
+           "include_global_state": false,
+           "rename_pattern": "(.+)",
+           "rename_replacement": "$1_restored_'$TIMESTAMP'"
+         }')
 
 echo "$RESTORE_P2" >> "$LOG_FILE"
+
 if echo "$RESTORE_P2" | grep -qi '\"error\"'; then
     log "ERROR: Full restore pass 2 failed"
     echo "Elasticsearch Response: $RESTORE_P2"
-    fail "Restore pass 2 failed"
+    fail "Restore PASS 2 failed"
 fi
 
-log "SNAPSHOT RESTORED SUCCESSFULLY"
+# ----------------------------------------------------------
+# COMPLETION
+# ----------------------------------------------------------
+log "=========== SNAPSHOT RESTORED SUCCESSFULLY ==========="
+log "Import directory: $IMPORT_DIR"
 exit 0
\ No newline at end of file
Index: /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/hive/controller/snapshot_controller.py
===================================================================
--- /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/hive/controller/snapshot_controller.py	(revision 2852)
+++ /branches/amp_3_7_2/src/webui/webui/htdocs/new/src/hive/controller/snapshot_controller.py	(working copy)
@@ -133,7 +133,6 @@
             start_date=start_date,
             end_date=end_date
         )
-        andebug('an.model.cli', result)
         error_msg = result.get("error") or result.get("stderr") or result.get("stdout") or ""
 
         if result.get("return_code") == 0:
@@ -161,11 +160,24 @@
 
     try:
         with open(LOG_FILE_IMPORT) as f:
-            lines = f.readlines()[-100:]  # read last 100 lines
+            lines = f.readlines()
 
+        # Find last import start marker
+        start_idx = None
+        for i in range(len(lines) - 1, -1, -1):
+            if "STARTING ELASTICSEARCH SNAPSHOT IMPORT" in lines[i]:
+                start_idx = i
+                break
+
+        # If no marker found, consider entire log
+        relevant_lines = lines[start_idx:] if start_idx is not None else lines
+
+        # Only inspect last N lines of the CURRENT run
+        relevant_lines = relevant_lines[-10:]
+
         result = {"status": "In Progress"}
 
-        for line in lines:
+        for line in relevant_lines:
             line_lower = line.lower()
             # Check for failures - look for "error:" to avoid matching "errors": false in JSON
             # Also check for "exception" for stack traces
@@ -198,11 +210,23 @@
 
     try:
         with open(LOG_FILE_EXPORT, "r") as f:
-            lines = f.readlines()[-100:]  # read last 100 lines
+            lines = f.readlines()
 
+        # Find last import start marker
+        start_idx = None
+        for i in range(len(lines) - 1, -1, -1):
+            if "STARTING ELASTICSEARCH SNAPSHOT EXPORT" in lines[i]:
+                start_idx = i
+                break
+
+        # If no marker found, consider entire log
+        relevant_lines = lines[start_idx:] if start_idx is not None else lines
+
+        # Only inspect last N lines of the CURRENT run
+        relevant_lines = relevant_lines[-10:]
         result = {"status": "In Progress"}
 
-        for line in lines:
+        for line in relevant_lines:
             line_lower = line.lower()
             # Check for failures
             if "error:" in line_lower or "exception" in line_lower:
