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='_';
datet=$(date +%Y"-"%m"-"%d" "%H":"%M":"%S"_%N ");
listdb="dblist.txt";
path="/backup/2024/07/08/teguhth"
dbname=teguhth
#echo "Start Restore Full & Transaction Log database '$dbname' from $path at $datet"
#echo ""
echo "List File Backup as: "
#cat $listdb
sed 's/^/* /' dblist.txt > hasil.txt
echo ""
cat hasil.txt
echo ""
echo "Size file backup:"
ls -lh $path
echo ""
echo "Start Restore Full & Transaction Log database '$dbname' from $path at $datet"
echo ""
for listdbs in $(cat $listdb | tr -d '\r')
do
datex=$(date +%Y"-"%m"-"%d" "%H":"%M":"%S"_%N ");
echo "Restore Transaction Log database '$dbname' from $path/$listdbs start at $datex"
gunzip -c < $path"/"$listdbs | mysql -uroot -root -f $dbname
done;
datez=$(date +%Y"-"%m"-"%d" "%H":"%M":"%S"_%N ");
echo ""
echo "Finished Restore Backup Full & Transaction Log database '$dbname' from $path at $datez"
echo ""
echo "Copyright by : Teguh Triharto"
echo "Website : https://www.linkedin.com/in/teguhth"
echo ""
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='_';
datet=$(date +%Y"-"%m"-"%d" "%H":"%M":"%S"_%N ");
listdb="dblist.txt";
path="/backup/2024/07/08/teguhth"
dbname=teguhth
#echo "Start Restore Full & Transaction Log database '$dbname' from $path at $datet"
#echo ""
echo "List File Backup as: "
#cat $listdb
sed 's/^/* /' dblist.txt > hasil.txt
echo ""
cat hasil.txt
echo ""
echo "Size file backup:"
ls -lh $path
echo ""
echo "Start Restore Full & Transaction Log database '$dbname' from $path at $datet"
echo ""
for listdbs in $(cat $listdb | tr -d '\r')
do
datex=$(date +%Y"-"%m"-"%d" "%H":"%M":"%S"_%N ");
echo "Restore Transaction Log database '$dbname' from $path/$listdbs start at $datex"
gunzip -c < $path"/"$listdbs | mysql -uroot -root -f $dbname
done;
datez=$(date +%Y"-"%m"-"%d" "%H":"%M":"%S"_%N ");
echo ""
echo "Finished Restore Backup Full & Transaction Log database '$dbname' from $path at $datez"
echo ""
echo "Copyright by : Teguh Triharto"
echo "Website : https://www.linkedin.com/in/teguhth"
echo ""
No comments:
Post a Comment