Friday, August 28, 2026

.::: Check ETA (Estimated Time of Arrival) restore status All Database / Reinisiasi MariaDB MarinaDB on Persent (%) for GTID Mirroring & Galera :::.

 
 
correlation with https://teguhth.blogspot.com/2026/07/check-eta-estimated-time-of-arrival.html

1. check dbsize all maria (only folder maria)

du -sch -- "/var/lib/mysql"/*/ | tail -1 | awk '{print $1}'
du -sc -- "/var/lib/mysql"/*/ | tail -1 | awk '{print $1}'

[root@teguhth-all ~]# du -sch -- "/var/lib/mysql"/*/ | tail -1 | awk '{print $1}'
3.7G
[root@teguhth-all ~]# du -sc -- "/var/lib/mysql"/*/ | tail -1 | awk '{print $1}'
3878576
[root@teguhth-all ~]#

 


2. recommendation drop all database no system

https://teguhth.blogspot.com/2025/10/script-drop-all-database-non-system-in.html 
 
3. restore alldb 

[root@teguhth etaini]# pwd
/data/etaini
[root@teguhth etaini]# sh res_iniisasi.sh sample_alldb.sql.gz
2026-08-28 16:30:54.935655862 ->>> Start Process
Fri Aug 28 16:30:54 WIB 2026
Restore Mulai



4. open new tab n run

[root@teguhth etaini]# pwd
/data/etaini
[root@teguhth etaini]# sh eta_all_reinisasi.sh 3879372
 

 

5. script to eta_all_reinisasi.sh

[root@teguhth etaini]# pwd
/data/etaini
[root@teguhth etaini]# cat eta_all_reinisasi.sh
#[root@teguhth-all eta]# sh eta_all_reinisasi.sh
# cat etamanual.sh

#!/bin/bash

## automatic
#db="$1"
sizedbsourcex="$1"

svrip=$(hostname -I | awk '{print $1}' | sed "s/ //g");
hostx=$(hostname -s);
datadirx='/var/lib/mysql'
osx=$(grep '^PRETTY_NAME=' /etc/os-release | cut -d= -f2- | tr -d '"')
dbv=$(systemctl show -p Description --value mariadb)

#sizedbsourcex from
#du -sch -- "/var/lib/mysql"/*/ | tail -1 | awk '{print $1}'
#du -sc -- "/var/lib/mysql"/*/ | tail -1 | awk '{print $1}'
# 3879372

## manual only test
#db="teguhth"
#sizedbsourcex=1987456

if [ -z "$sizedbsourcex" ]; then
    echo "ERROR: Ukuran database source belum diisi."
    echo "Usage: $0 <nama_database> <size_db_source>"
    exit 1
fi

prev_size=0
prev_time=$(date +%s)

while true
do
    #sizedbdestx=$(du -s $datadirx | awk '{print $1}')
sizedbdestx=$(du -s -- "$datadirx"/*/ | awk '{sum += $1} END {print sum}')

    progresx=$(awk "BEGIN {printf \"%.2f\", $sizedbdestx * 100 / $sizedbsourcex}")
    percent=$(awk "BEGIN {printf \"%d\", $sizedbdestx * 100 / $sizedbsourcex}")

    [ "$percent" -gt 100 ] && percent=100

    width=50
    filled=$((percent * width / 100))
    empty=$((width - filled))

    bar=$(printf "%${filled}s" | tr ' ' 'o')

    now=$(date +%s)
    elapsed=$((now - prev_time))

    if [ "$elapsed" -gt 0 ]; then
        diff=$((sizedbdestx - prev_size))
        speed_kb=$((diff / elapsed))
    else
        speed_kb=0
    fi

        # Hitung ETA
remaining_kb=$((sizedbsourcex - sizedbdestx))

# Sisa size
remaining_mb=$(awk "BEGIN {printf \"%.2f\", $remaining_kb/1024}")
remaining_gb=$(awk "BEGIN {printf \"%.2f\", $remaining_kb/1024/1024}")

# Source & Destination dalam GB
source_gb=$(awk "BEGIN {printf \"%.2f\", $sizedbsourcex/1024/1024}")
dest_gb=$(awk "BEGIN {printf \"%.2f\", $sizedbdestx/1024/1024}")


if [ "$speed_kb" -gt 0 ]; then
    eta_sec=$((remaining_kb / speed_kb))

    eta_h=$((eta_sec / 3600))
    eta_m=$(((eta_sec % 3600) / 60))
    eta_s=$((eta_sec % 60))
else
    eta_h=0
    eta_m=0
    eta_s=0
fi

# Perkiraan waktu selesai
if [ "$speed_kb" -gt 0 ]; then
    finish_time=$(date -d "+$eta_sec seconds" "+%Y-%m-%d %H:%M:%S")
    finish_clock=$(date -d "+$eta_sec seconds" "+%H:%M:%S")
else
    finish_time="-"
    finish_clock="-"
fi

 # persekarang
    speed_mb=$(awk "BEGIN {printf \"%.2f\", $speed_kb/1024}")

        #backup_proc=$(pgrep -af "mysqldump|mariadb-dump")
#restore_proc=$(pgrep -af "mysql|mariadb" | grep -F "$db")
restore_procdb=$(pgrep -af "mysql|mariadb"  | grep -E '(^| )-f( |$)')

dbprog=$(find "$datadirx" -mindepth 1 -maxdepth 1 -type d \
    -printf "%T@ %f\n" |
    sort -nr |
    head -1 |
    awk '{print $2}')

dbokx=$(ls -dt /var/lib/mysql/*/ | sed 's#^/var/lib/mysql/##; s#/$##' | paste -sd,)
dbtotx=$(ls -d /var/lib/mysql/*/ | wc -l)
clear
datex=$(date)
echo ".::: Progres Restore '$datadirx' Reinisasi Slave at $datex ::::."
echo
echo "Host Server Target  : $hostx"
echo "IP Server Target    : $svrip"
echo "Database Product    : $dbv"
echo "Progres Restore to  : $datadirx with '$dbprog'"
echo "Source DBSize       : $sizedbsourcex KB (${source_gb} GB)"
echo "Destination DBSize  : $sizedbdestx KB (${dest_gb} GB)"
echo "Remaining DBSize    : $remaining_kb KB (${remaining_gb} GB)"

echo "Progress            : $progresx %"
echo "Restore Speed       : $speed_kb KB/s ($speed_mb MB/s)"
printf "ETA                 : %02d:%02d:%02d\n" $eta_h $eta_m $eta_s
echo "Finish At           : $finish_time"
#echo "Finish At          : $finish_clock"
printf "Progress Bar        : [%-50s] %6.2f%%\n" "$bar" "$progresx"
echo
echo "Database Complete   : ('$dbtotx'db)-=> $dbokx"
echo ""
echo "Copyright by        : Teguh Triharto"
echo "Website             : https://www.linkedin.com/in/teguhth"
echo "Operating System    : $osx"
echo

if [ -n "$restore_procdb" ]; then
    echo "Running Reiniasi '$dbprog' '$restore_procdb' "
        echo
    show_progress=1

else
    echo "IDLE - Tidak ada proses BACKUP maupun RESTORE untuk database '$restore_procdb'"
        echo
fi

#echo "check Progres database Maria '$dbprog' in unit sort by size"
#echo
#du -sh -- "$datadirx"/*/ | sort -hr | head -5



echo "check Progres file Maria '$dbprog' in unit"
echo
find "$datadirx/$dbprog" -type f \
    -printf "%TY-%Tm-%Td %TH:%TM:%TS %s %p\n" |
    sort -r |
    head -5 |
    while read d t s f
    do
        printf "%s %s %10s (%15s bytes) %s\n" \
            "$d" "$t" \
            "$(numfmt --to=iec-i --suffix=B "$s")" \
            "$s" \
            "$f"
    done
echo


echo "check Progres database Maria '$dbprog' in unit sort new create"
echo
find "$datadirx" -mindepth 1 -maxdepth 1 -type d \
    -printf "%T@ %TY-%Tm-%Td %TH:%TM:%TS %p\n" |
    sort -nr |
    head -5 |
    while read epoch date time dir
    do
        size=$(du -sb "$dir" | awk '{print $1}')
        printf "%s %s %10s (%15s bytes) %s\n" \
            "$date" "$time" \
            "$(numfmt --to=iec-i --suffix=B "$size")" \
            "$size" \
            "$dir"
    done

#echo "check Progres database Maria '$dbprog' in unit sort by size"

#echo
#find "$datadirx" -mindepth 1 -maxdepth 1 -type d \
#    -printf "%T@ %TY-%Tm-%Td %TH:%TM:%TS %p\n" |
#    sort -nr |
 #   head -5 |
 #   while read epoch date time dir
 #   do
#        size=$(du -sb "$dir" | awk '{print $1}')
#        printf "%s %s %10s (%15s bytes) %s\n" \
#            "$date" "$time" \
#            "$(numfmt --to=iec-i --suffix=B "$size")" \
 #           "$size" \
  #          "$dir"
#    done
    prev_size=$sizedbdestx
    prev_time=$now

    sleep 2
done
[root@teguhth etaini]#



No comments:

Post a Comment

Popular Posts