Friday, June 19, 2026

.::: Check progress restore and backup status MariaDB MarinaDB :::.

  

1. check folder size

watch du -s /var/lib/mysql/teguhth
 

 
2. check folder size using unit 

watch du -sh /var/lib/mysql/teguhth
 

3. check pogress file 


watch 'find /var/lib/mysql/teguhth -type f -printf "%TY-%Tm-%Td %TH:%TM:%TS %p\n" | sort -r | head'
 

4. check pogress file byte


watch 'find /var/lib/mysql/teguhth -type f -printf "%TY-%Tm-%Td %TH:%TM:%TS %12s %p\n" | sort -r | head'
 

5. check pogress file in unit 

watch 'find /var/lib/mysql/teguhth -type f -printf "%TY-%Tm-%Td %TH:%TM:%TS %s %p\n" | sort -r | head | while read d t s f; do printf "%s %s %8s %s\n" "$d" "$t" "$(numfmt --to=iec-i --suffix=B "$s")" "$f"; done'
 
 
6. if create script
 
 [root@teguhth]#
#!/bin/bash

pathdata="/var/lib/mysql"

datex=$(date +"%Y%m%d_%H%M%S")

ip_svr=$(hostname -I | awk '{print $1}' | sed "s/ //g");


db="${1}"

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

echo ".::: Check Progres Restore Maria in IP $ip_svr at $datex :::."
echo
echo "Proccess Restore"
echo
#ps -ef | grep '[m]ysql -u' | grep -i mysqldump
#ps -ef | grep $db
#ps -ef | grep "[m]ysql -u.*$db"
ps -ef | grep '[m]ysql -u'
ps -ef | grep '[m]ariadb -u'
 
pgrep -af 'mysql|mariadb' | grep -F "$db"
  
echo "backup '$db'"
pgrep -af 'mysqldump|mariadb-dump' | grep -F "$db"
echo

echo
#
#if pgrep -af "mysql -u.*$db" >/dev/null; then
#    echo "Restore/import masih berjalan"
#else
#    echo "Restore/import sudah selesai"
#fi

echo
echo "uptime Maria"
systemctl status mariadb | grep Active
echo

echo "Folder Size Maria Progres '
$db'"
echo
du -s "$pathdata/$db"

echo
echo "Folder Size Maria Progres '
$db'"
du -h "$pathdata/$db"

echo
echo "check Progres file Maria '
$db' in unit"
echo
find "$pathdata/$db" -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 %8s %s\n" \
            "$d" "$t" \
            "$(numfmt --to=iec-i --suffix=B "$s")" \
            "$f"
    done
echo
echo "check Sort file Maria '
$db' in unit"
echo
find "$pathdata/$db" -type f \
    -printf '%s\t%p\n' |
    sort -nr |
    head -5 |
    numfmt --field=1 --to=iec --padding=8
 
echo "Copyright by           : Teguh Triharto"
echo "Website                : https://www.linkedin.com/in/teguhth"
echo ""
grep '^PRETTY_NAME=' /etc/os-release | cut -d= -f2- | tr -d '"'
 
[root@teguhth]# 
 


7. check using script advanced 
 
sh /data/check_backup_restore_status.sh
 
[root@/data]#  watch sh check_backup_restore_status.sh teguhth
#!/bin/bash

pathdata="/var/lib/mysql"

#datex=$(date +"%Y%m%d_%H%M%S")
datex=$(date)

ip_svr=$(hostname -I | awk '{print $1}')

db="$1"

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

echo ".::: Check Progres Maria '$db' in IP $ip_svr at $datex :::."
echo

###############################
# CHECK BACKUP / RESTORE
###############################

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

show_progress=0

if [ -n "$backup_proc" ]; then
    echo "Proses BACKUP database '$db' sedang berjalan"
    echo "$backup_proc"

elif [ -n "$restore_proc" ]; then
    echo "Proses RESTORE database '$db' sedang berjalan"
    echo "$restore_proc"
    show_progress=1

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

echo
echo "uptime Maria"
systemctl status mariadb --no-pager | grep Active
echo

########################################################
# HANYA TAMPIL SAAT RESTORE
########################################################

if [ "$show_progress" -eq 1 ]; then

    ###############################
    # FOLDER SIZE
    ###############################

    echo "Folder Size Maria Progres '$db'"
    echo

    du -s "$pathdata/$db" 2>/dev/null \
        | awk '{printf "%-15s %s\n",$1,$2}'

    du -sh "$pathdata/$db" 2>/dev/null \
        | awk '{printf "%-15s %s\n",$1,$2}'

    echo

    ###############################
    # FILE TERBARU
    ###############################

    echo "check Progres file Maria '$db' in unit"
    echo

    find "$pathdata/$db" -type f \
        -printf "%TY-%Tm-%Td %TH:%TM:%TS %s %p\n" 2>/dev/null |
        sort -r |
        head -5 |
        while read d t s f
        do
            printf "%s %s %8s %s\n" \
                "$d" \
                "$t" \
                "$(numfmt --to=iec-i --suffix=B "$s")" \
                "$f"
        done

    echo

    ###############################
    # FILE TERBESAR
    ###############################

    echo "check Sort file Maria '$db' in unit"
    echo

    find "$pathdata/$db" -type f \
        -printf '%s\t%p\n' 2>/dev/null |
        sort -nr |
        head -5 |
        numfmt --field=1 --to=iec --padding=8

    echo

fi

echo "Copyright by           : Teguh Triharto"
echo "Website                : https://www.linkedin.com/in/teguhth"
echo
grep '^PRETTY_NAME=' /etc/os-release | cut -d= -f2- | tr -d '"'

[root@/data]# 

 

 

8. check reiniasi slave 
 
[root@teguhth-all progres]# pwd
/data/progres
[root@teguhth-all progres]# cat cek_reinisiasi_persenonly.sh
#!/bin/bash

datadirx="/var/lib/mysql"
datex=$(date)

# Ukuran database sumber (KB)
#sizedbsourcex=1987456
sizedbsourcex=${1}

if [ -z "$sizedbsourcex" ]; then
    echo "ERROR: Size database asal belum diisi."
    echo "Usage: $0 <dbsize>"
    exit 1
fi

# Ukuran database tujuan (KB)
sizedbdestx=$(du -s $datadirx | awk '{print $1}')

# Hitung persen (2 desimal)
progresx=$(awk "BEGIN {printf \"%.2f\", $sizedbdestx * 100 / $sizedbsourcex}")

# Persen bulat untuk progress bar
percent=$(awk "BEGIN {printf \"%d\", $sizedbdestx * 100 / $sizedbsourcex}")

# Batasi maksimum 100%
if [ "$percent" -gt 100 ]; then
    percent=100
fi

# Panjang progress bar
width=50

# Hitung jumlah karakter terisi
filled=$((percent * width / 100))
empty=$((width - filled))

# Buat progress bar
bar=$(printf "%${filled}s" | tr ' ' 'o')
space=$(printf "%${empty}s")

ip_svr=$(hostname -I | awk '{print $1}' | sed "s/ //g");
echo ""
echo "reinisiasi to >>> $ip_svr $datex"
echo ""

echo "Source DB Size      : $sizedbsourcex KB"
echo "Destination DB Size : $sizedbdestx KB"
echo "Progress            : $progresx%"
printf "Progress Bar        : [%-50s]\n"  "$bar"

restore_proc=$(pgrep -af "mysql|mariadb" | grep -E '(^| )-f( |$)')
echo "$restore_proc"
  echo "Folder Size Maria Progres reinisiasi '$datadirx'"
    echo

    du -s "$datadirx" 2>/dev/null \
        | awk '{printf "%-15s %s\n",$1,$2}'

    du -sh "$datadirx" 2>/dev/null \
        | awk '{printf "%-15s %s\n",$1,$2}'
    echo
find $datadirx -mindepth 1 -maxdepth 1 -type d -printf '%TY-%Tm-%Td %TH:%TM:%TS %p\n' | sort -r | head -5
echo ""
echo "Copyright by           : Teguh Triharto"
echo "Website                : https://www.linkedin.com/in/teguhth"
echo ""
[root@teguhth-all progres]#

 

 
 

No comments:

Post a Comment

Popular Posts