correlation https://teguhth.blogspot.com/2026/06/check-progress-restore-status-mariadb.html
1. check sourcedata full database
du -s /var/lib/mysql/teguhth
du -sh /var/lib/mysql/teguhth
[root@teguhth-all eta]# du -s /var/lib/mysql/teguhth
570752 /var/lib/mysql/teguhth
[root@teguhth-all eta]#
[root@teguhth-all eta]# du -sh /var/lib/mysql/teguhth
558M /var/lib/mysql/teguhth
[root@teguhth-all eta]#
2. check sourcedata size exclude sample
du -s --exclude='pembelian.ibd' /var/lib/mysql/teguhth
du -s --exclude='pembelian.ibd' --exclude='pasok.ibd' /var/lib/mysql/teguhth
3. for simulation change
dd if=AlmaLinux-9.6-x86_64-minimal.iso bs=1M | pv -L 10m | dd of=/var/lib/mysql/teguhth/contract.ibd
4. run script eta_manual_restore.sh , asumsi sudah dibackup sebelum restore
sh eta_manual_restore.sh teguhth 2562432
5. capture result progres
6. script eta_manual_restore.sh
[root@teguhth-all eta]# pwd
/data/eta
[root@teguhth-all eta]#
[root@teguhth-all eta]# cat eta_manual_restore.sh
# cat etamanual.sh
#!/bin/bash
## automatic
db="$1"
sizedbsourcex="$2"
svrip=$(hostname -I | awk '{print $1}' | sed "s/ //g");
hostx=$(hostname -s);
datadirx='/var/lib/mysql'
## manual only test
#db="teguhth"
#sizedbsourcex=1987456
if [ -z "$db" ]; then
echo "ERROR: Nama database belum diisi."
echo "Usage: $0 <nama_database> <size_db_source>"
echo "Usage: $0 <dbsf_nbc_xxxx> <21426936>"
exit 1
fi
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/$db | awk '{print $1}')
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}")
clear
datex=$(date)
echo ".::: Progres Restore '$db' at $datex ::::."
echo
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 "Host Server Target : $hostx"
echo "IP Server Target : $svrip"
echo "Database Restore to : $db"
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 "Copyright by : Teguh Triharto"
echo "Website : https://www.linkedin.com/in/teguhth"
echo ""
prev_size=$sizedbdestx
prev_time=$now
sleep 2
done
[root@teguhth-all eta]#






No comments:
Post a Comment