]> Git [git.vados.ru] :: Repos - Mikrotiks/Mikrotiks.git/commitdiff
Autocommit in repo: , generated by owner: mikro_bak, in 13:00:03 12.03.2026.
authorvados-dev <vados@vados.ru>
Thu, 12 Mar 2026 10:00:03 +0000 (13:00 +0300)
committervados-dev <vados@vados.ru>
Thu, 12 Mar 2026 10:00:03 +0000 (13:00 +0300)
bin/Binary.backup
bin/ros-diff.sh

index 34a09ac3c330435d5488b8bada6d17073d21e570..51950d30e4865d68e767d5ab4e321f72934d3eb4 100644 (file)
Binary files a/bin/Binary.backup and b/bin/Binary.backup differ
index a62a2dfdd4cedfad9c50b58e17622328dc800590..20950c8fbf78bcf216129cd808fada0f8e933956 100755 (executable)
@@ -116,7 +116,6 @@ section() {
     echo -e "\n${magenta}................[$(tput rev) $* ${reset}${magenta}]................${reset}\n"
 }
 
-
 spinstr()
 {
   local -r pid="${1}"
@@ -131,7 +130,7 @@ spinstr()
     sleep "${delay}"
     printf "\b\b\b\b\b\b"
   done
-  echo -ne "\\r[ ✔ ]\\n" #"    \b\b\b\b"
+  echo -ne "\\r[ ✔ ]\\n"
 tput cnorm --
 }
 
@@ -271,8 +270,11 @@ run_ssh_cmd() {
 download_config() {
     local conf="${1}"
     local log_msg
-
-    if ${SSH_STR} export >${conf}; then
+    ${SSH_STR} export >${conf} >/dev/null & pid=$!
+    spinstr "$pid"
+    wait "$pid"
+    rc=$?
+    if [ $rc -eq 0 ]; then
         log_msg="- Config download success!"
         log_success "${log_msg}"
         return 0
@@ -289,9 +291,8 @@ compare_config() {
     local diff_file="${3}"
     local diff_args=("${DEFAULT_DIFF_ARGS[@]}")
     local log_msg
-    warning "diff ${diff_args[*]} ${config_file} ${precedent_file} > ${diff_file}"
+
     diff "${diff_args[@]}" ${config_file} ${precedent_file} >${diff_file}
-    exit 0
     if [ "$?" -ne "0" ]; then
         log_msg="- There is a difference! Create backup..."
         if [ -t 1 ] && $DEBUG_OUT; then
@@ -302,11 +303,11 @@ compare_config() {
         return 0
     else
         log_msg="- The files are identical. No backup is required."
+        log_info "${log_msg}"
         if [ -t 1 ] && $DEBUG_OUT; then
             section " START CLEANUP "
             sleep 1
         fi
-        log_info "${log_msg}"
         log_msg="- Remove ${diff_file} file."
         log_info "${log_msg}"
         ${CMD_RM} -f ${diff_file}
@@ -342,10 +343,6 @@ check_directory() {
  fi
 }
 
-    # Examples:
-    # bin_pass="$(${SSH_STR} ':put [/system script environment get [find name=BackupPassword] value]')"
-    # bin_pass="$(${SSH_STR} ':put $BackupPassword')"  # if BackupPassword is a global
-
 backup_binary() {
     local bin_name="${1}"
     local bin_pass="${2:-$DEFAULT_BINPWD}"
@@ -353,7 +350,9 @@ backup_binary() {
     local bin_tmp="Binary.backup"
     local log_msg
     local crypt_str
-    
+    # Examples:
+    # bin_pass="$(${SSH_STR} ':put [/system script environment get [find name=BackupPassword] value]')"
+    # bin_pass="$(${SSH_STR} ':put $BackupPassword')"  # if BackupPassword is a global
     if [ -n "$(${SSH_STR} ':put $BackupEncrypt')" ] && [ -n "$(${SSH_STR} ':put $BackupPassword')" ] ; then
         crypt_str="dont-encrypt=no password=$(${SSH_STR} ':put $BackupPassword')"
     else
@@ -364,19 +363,25 @@ backup_binary() {
         fi
     fi
     
-    local BKPSTR="/system backup save name=${bin_tmp} ${crypt_str}"
-    local T_BKPCLN="/file remove [find name=${bin_tmp}]"
-    ${SSH_STR} "/system backup save name=${bin_tmp} ${crypt_str}" >/dev/null & spinstr "$!"
-    if [ $? -eq 0 ]; then
+    log_msg="Create ${bin_tmp} file on ${RouterName}..."
+    log_info "${log_msg}"
+
+    ${SSH_STR} "/system backup save name=${bin_tmp} ${crypt_str}" >/dev/null & pid=$!
+    spinstr "$pid"
+    wait "$pid"
+    rc=$?
+    if [ $rc -eq 0 ]; then
         log_msg="Create binary backup ${bin_tmp} on ${RouterName} success."
         log_success "${log_msg}"
 
         log_msg="- Start download ${bin_tmp} file to ${BackupDir}..."
         log_info "${log_msg}"
         
-        ${SCP_STR}:/${bin_tmp} ${bin_name} & spinstr "$!"
-        if [ $? -eq 0 ]; then
-            sleep 2
+        ${SCP_STR}:/${bin_tmp} ${bin_name} >/dev/null & pid=$!
+        spinstr "$pid"
+        wait "$pid"
+        rc=$?
+        if [ $rc -eq 0 ]; then
             log_msg="- Binary Backup download complete!"
             log_success "${log_msg}"
         else
@@ -395,16 +400,15 @@ backup_binary() {
     log_info "${log_msg}"
    
     if ${SSH_STR} "/file remove [find name=${bin_tmp}]"; then
-    log_msg="- Remove ${bin_tmp} file on ${RouterName} complete succesfully!"
-    log_success "${log_msg}"
+        log_msg="- Remove ${bin_tmp} file on ${RouterName} complete succesfully!"
+        log_success "${log_msg}"
     else
-    log_msg="- Error Remove ${bin_tmp} file on ${RouterName}!"
-    log_error "${log_msg}"
+        log_msg="- Error Remove ${bin_tmp} file on ${RouterName}!"
+        log_error "${log_msg}"
     fi
 }
 
 readarray -t lines < $HostsFile
-
 for HR in "${lines[@]}"; do
 while IFS=$' ' read -a HR ; do
 [[ -z ${HR[0]} ]] && continue
@@ -419,12 +423,6 @@ SSHuser=${HR[3]}
 backup_pass=${HR[4]}
 
 get_connections_str
-#backup_binary "BinaryTest.backup"
-
-#exit 0
-#warning "SSH_STR = ${SSH_STR}"
-#warning "SCP_STR = ${SCP_STR}"
-#exit 0
 
 BaseDir=${HomeDir}"/backups/${RouterName}/"
 TempDir=${BaseDir}"tmp/"
@@ -491,14 +489,10 @@ if compare_config ${current_config} ${precedent_config} ${diff_config} ${RouterN
     log_msg="- Copy configuration to ${BackupDir}/${save_config} and ${precedent_config} success."
     log_success "${log_msg}"
 
-    log_msg="Create ${bin_tmp} file on ${RouterName}..."
-    log_info "${log_msg}"
-
     backup_binary ${bin_tmp} ${backup_pass}
-#    if [ $? -eq 0 ]; then
-
+  
     cd "${BaseDir}"
-
+  
     CurrentHistoryDir=${HistoryDir}"${DStamp}/"
     ${CMD_MKD} -p ${CurrentHistoryDir}
     diff_config_history=${CurrentHistoryDir}"${DTStamp}-Diff-Config.rsc"
@@ -553,8 +547,6 @@ log_success "${log_msg}"
 done <<<"$(echo -e $HR)"
 LogFile="${DEFAULT_LOG}"
 RouterName=""
-#  echo -ne "\\r[${BAR_SIZE:0:percBar}] $perc %"
-#echo "[] $perc %"
 done
 
 if [ -t 1 ] && $DEBUG_OUT; then