Saturday, February 17, 2024

.::: Script to Restore Backup Full & all Transaction in one Command for MariaDB MySQL :::.

1. check before restore
2. check directory backup & create dblist,txt

ls > dblist.txt

[root@teguhth teguhth]# ls > dblist.txt
[root@teguhth teguhth]# cat dblist.txt
dblist.txt
[FULL]_teguhth_20240217_155359.sql.gz
[LOG]_teguhth_20240217_155414.sql.gz
[LOG]_teguhth_20240217_185039.sql.gz
[LOG]_teguhth_20240217_185041.sql.gz
read.sh
test.sh


3. editing base on file will be restore
[root@teguhth teguhth]# cat dblist.txt
[FULL]_teguhth_20240217_155359.sql.gz
[LOG]_teguhth_20240217_155414.sql.gz
[LOG]_teguhth_20240217_185039.sql.gz
[LOG]_teguhth_20240217_185041.sql.gz
[root@teguhth teguhth]#

4. create script to restore all file

[root@teguhth teguhth]# cat restore_full_all_log.sh

echo ""
Server=$(hostname)
ip_address=$(ip a | awk '/inet / && $2 !~ /^127\./ {gsub("addr:","",$2); print $2}')
# Print the IP address

infotgl=$(date)
dbversion=$(mysql -uroot -proot -sNe "select @@version as VersionDB");
echo ".::: Restore Transaction Log Backup MariaDB / MySQL using custom in '$Server $dbversion' with $ip_address :::."
echo ""
#!/bin/bash
#
#clear;
year=`date +%Y`; month=`date +%m`; day=`date +%d`; hour=`date +%H`; min=`date +%M`; sec=`date +%S`; dayname=`date +%a`;underscore='_';

listdb="dblist.txt";
path="/backup/20240217/teguhth"
dbname=teguhth
echo "List File Backup as "

cat $listdb

echo ""
for listdbs in  $(cat $listdb | tr -d '\r')
do
echo "Restore Transaction Log database '$dbname' from $path start at $year$month$day$underscore$hour$min$sec"

  gunzip -c < $path"/"$listdbs | mysql -uroot -root -f $dbname

done;

echo "Finished Restore Transaction Log database '$dbname' from $path at $year$month$day$underscore$hour$min$sec"
echo ""
echo "Copyright by           : Teguh Triharto"
echo "Website                : https://www.linkedin.com/in/teguhth"
echo ""
[root@teguhth teguhth]#


5. run restore restore_full_all_log.sh
 

6. check after restore


No comments:

Post a Comment

Popular Posts