Переглянути джерело

2020/11/14 23:55:31

master
Gitea 5 роки тому
джерело
коміт
e3a50000c7

+ 6
- 6
01.ENV_check.sh Переглянути файл

@@ -334,13 +334,13 @@ SEL_REMOTE_BAK (){
echo -e -n "\033[33m1. Do you want to enable \033[35mPlan#X\033[0m? (y|n) "
read yn
if [[ $yn == y ]]; then
echo -e " Your input is y. Enabling the PLAN#X..."
echo -e " \033[32m>> Your input is y. Enabling the PLAN#X... \033[0m"
sed -i 's/#MKDIR_REMOTE_BAK_Folder_BAK_Disk_X/MKDIR_REMOTE_BAK_Folder_BAK_Disk_X/g' $Script_TMP_Remote_Backup
sed -i 's/#SCP_TO_BAK_Disk_X/SCP_TO_BAK_Disk_X/g' $Script_TMP_Remote_Backup
elif [[ $yn == n ]]; then
echo -e " Your input is n. Disabling the PLAN#Y..."
echo -e " \033[35m>> Your input is n. Disabling the PLAN#Y... \033[0m"
else
echo -e " \033[31mWrong inout($yn). Exit \033[0m"
echo -e " \033[31m>> Wrong inout($yn). Exit \033[0m"
echo
exit
fi
@@ -348,13 +348,13 @@ SEL_REMOTE_BAK (){
echo -e -n "\033[33m2. Do you want to enable \033[36mPlan#Y\033[0m? (y|n) "
read yn
if [[ $yn == y ]]; then
echo -e " Your input is y. Enabling the PLAN#Y..."
echo -e " \033[32m>> Your input is y. Enabling the PLAN#Y... \033[0m"
sed -i 's/#MKDIR_REMOTE_BAK_Folder_BAK_Disk_Y/MKDIR_REMOTE_BAK_Folder_BAK_Disk_Y/g' $Script_TMP_Remote_Backup
sed -i 's/#SCP_TO_BAK_Disk_Y/SCP_TO_BAK_Disk_Y/g' $Script_TMP_Remote_Backup
elif [[ $yn == n ]]; then
echo -e " Your input is n. Disabling the PLAN#Y..."
echo -e " \033[35m>> Your input is n. Disabling the PLAN#Y... \033[0m"
else
echo -e " \033[31mWrong inout($yn). Exit \033[0m"
echo -e " \033[31m>> Wrong inout($yn). Exit \033[0m"
echo
exit
fi

+ 49
- 57
02.AutoBackup_crontab_check.sh Переглянути файл

@@ -3,90 +3,82 @@ Service1=/ED/ED8/Script_ED8/ED8backup-mysql-Auto.sh
Service2=/ED/ED8/Script_ED8/ED8backup-Script_ED8-Auto.sh
Service3=/ED/ED8/Script_ED8/ED8backup-Source_Files-Auto.sh
Service4=/ED/ED8/Script_ED8/ED8Remote_backup.sh

Service5=/ED/ED8/Script_ED8/ED8backup-attachment-Auto.sh
Service6=/ED/ED8/Script_ED8/ED8backup-attachment-rsync-Auto.sh
WHO=`whoami`

crontab -u $WHO -l
echo
crontab -u $WHO -l; echo
crontab -u $WHO -l | grep "$Service1" > /dev/null 2>&1
if [[ $? == 0 ]]; then
crontab -u $WHO -l | grep "$Service1" | cut -c 1-8 | grep "#"
if [[ $? != 0 ]]; then
echo -e "\033[33mPass. $Service1 was set active. \033[0m"
else
echo -e "\033[45;37mWarning! $Service1 was appended, but not be set as executing. \033[0m"
if [[ $? == 0 ]]; then crontab -u $WHO -l | grep "$Service1" | cut -c 1-8 | grep "#"
if [[ $? != 0 ]]; then echo -e "\033[33mPass. $Service1 was set active. \033[0m"
else echo -e "\033[45;37mWarning! $Service1 was appended, but not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m#// Create backup file every 2 days at 01:08\033[0m"
echo -e "\033[33m8 1 */2 * * $Service1\033[0m"

echo -e "\033[33m8 1 * * * $Service1\033[0m"
fi
else
echo -e "\033[41;37mFail. $Service1 was not be set as executing. \033[0m"
else echo -e "\033[41;37mFail. $Service1 was not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m#// Create backup file every 2 days at 01:08\033[0m"
echo -e "\033[33m8 1 */2 * * $Service1\033[0m"
echo -e "\033[33m8 1 * * * $Service1\033[0m"
fi
echo

crontab -u $WHO -l | grep "$Service2" > /dev/null 2>&1
if [[ $? == 0 ]]; then
crontab -u $WHO -l | grep "$Service2" | cut -c 1-8 | grep "#"
if [[ $? != 0 ]]; then
echo -e "\033[33mPass. $Service2 was set active. \033[0m"
else
echo -e "\033[45;37mWarning! $Service2 was appended, but not be set as executing. \033[0m"
if [[ $? == 0 ]]; then crontab -u $WHO -l | grep "$Service2" | cut -c 1-8 | grep "#"
if [[ $? != 0 ]]; then echo -e "\033[33mPass. $Service2 was set active. \033[0m"
else echo -e "\033[45;37mWarning! $Service2 was appended, but not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m#// Create backup file every first day of month at 01:06"
echo -e "\033[33m6 1 1 * * $Service2\033[0m"

echo -e "\033[33m0 1 1 * * $Service2\033[0m"
fi
else
echo -e "\033[41;37mFail. $Service2 was not be set as executing. \033[0m"
else echo -e "\033[41;37mFail. $Service2 was not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m#// Create backup file every first day of month at 01:06"
echo -e "\033[33m6 1 1 * * $Service2\033[0m"
echo -e "\033[33m0 1 1 * * $Service2\033[0m"
fi
echo

crontab -u $WHO -l | grep "$Service3" > /dev/null 2>&1
if [[ $? == 0 ]]; then
crontab -u $WHO -l | grep "$Service3" | cut -c 1-8 | grep "#"
if [[ $? != 0 ]]; then
echo -e "\033[33mPass. $Service3 was set active. \033[0m"
else
echo -e "\033[45;37mWarning! $Service3 was appended, but not be set as executing. \033[0m"
if [[ $? == 0 ]]; then crontab -u $WHO -l | grep "$Service3" | cut -c 1-8 | grep "#"
if [[ $? != 0 ]]; then echo -e "\033[33mPass. $Service3 was set active. \033[0m"
else echo -e "\033[45;37mWarning! $Service3 was appended, but not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m#// Create backup file every first day of month at 01:00"
echo -e "\033[33m0 1 1 * * $Service3\033[0m"

echo -e "\033[33m2 1 1 * * $Service3\033[0m"
fi
else
echo -e "\033[41;37mFail. $Service3 was not be set as executing. \033[0m"
else echo -e "\033[41;37mFail. $Service3 was not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m#// Create backup file every first day of month at 01:00"
echo -e "\033[33m0 1 1 * * $Service3\033[0m"
echo -e "\033[33m2 1 1 * * $Service3\033[0m"
fi
echo

crontab -u $WHO -l | grep "$Service4" > /dev/null 2>&1
if [[ $? == 0 ]]; then
crontab -u $WHO -l | grep "$Service4" | cut -c 1-8 | grep "#" > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e "\033[33mPass. $Service4 was set active. \033[0m"
else
echo -e "\033[45;37mWarning! $Service4 was appended, but not be set as executing. \033[0m"
if [[ $? == 0 ]]; then crontab -u $WHO -l | grep "$Service4" | cut -c 1-8 | grep "#" > /dev/null 2>&1
if [[ $? != 0 ]]; then echo -e "\033[33mPass. $Service4 was set active. \033[0m"
else echo -e "\033[45;37mWarning! $Service4 was appended, but not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m#// Create backup file every Monday 06:00"
echo -e "\033[33m0 6 * * 1 $Service4\033[0m"

fi
else
echo -e "\033[41;37mFail. $Service4 was not be set as executing. \033[0m"
else echo -e "\033[41;37mFail. $Service4 was not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m#// Create backup file every Monday 06:00"
echo -e "\033[33m0 6 * * 1 $Service4\033[0m"
fi
echo

crontab -u $WHO -l | grep "$Service5" > /dev/null 2>&1
if [[ $? == 0 ]]; then crontab -u $WHO -l | grep "$Service5" | cut -c 1-8 | grep "#" > /dev/null 2>&1
if [[ $? != 0 ]]; then echo -e "\033[33mPass. $Service5 was set active. \033[0m"
else echo -e "\033[45;37mWarning! $Service5 was appended, but not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m0 6 1 * * $Service5\033[0m"
fi
else echo -e "\033[41;37mFail. $Service5 was not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m0 6 1 * * $Service5\033[0m"
fi

crontab -u $WHO -l | grep "$Service6" > /dev/null 2>&1
if [[ $? == 0 ]]; then crontab -u $WHO -l | grep "$Service6" | cut -c 1-8 | grep "#" > /dev/null 2>&1
if [[ $? != 0 ]]; then echo -e "\033[33mPass. $Service6 was set active. \033[0m"
else echo -e "\033[45;37mWarning! $Service6 was appended, but not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m30 1 * * * $Service6\033[0m"
fi
else echo -e "\033[41;37mFail. $Service6 was not be set as executing. \033[0m"
echo -e "Please add below info by command \033[32m\"crontab -u $WHO -e\"\033[0m"
echo -e "\033[33m30 1 * * * $Service6\033[0m"
fi;

echo


+ 9
- 11
ED8Remote_backup.sh Переглянути файл

@@ -12,7 +12,8 @@ fi

BAK_Project=ED8
WHO=`whoami`
HOSTNAME=`hostnamectl | grep "Static hostname" | awk '{print $NF}'`
#HOSTNAME=`hostnamectl | grep "Static hostname" | awk '{print $NF}'`
HOSTNAME=`hostname`
TS=`date +"%Y%m%d-%H%M%S"`

# Host Local Backup info setup
@@ -106,9 +107,8 @@ CHK_BAK1 (){
if [[ $? == 0 ]]; then
echo -e " \033[34mPass. \033[0m"
else
echo -e " \033[31mFail. Exit.\033[0m"
echo -e " \033[33mWarning! There is no local backup file ($BAK_1).\033[0m"
echo
exit
fi
}

@@ -118,9 +118,8 @@ CHK_BAK2 (){
if [[ $? == 0 ]]; then
echo -e " \033[34mPass. \033[0m"
else
echo -e " \033[31mFail. Exit.\033[0m"
echo -e " \033[33mWarning! There is no local backup file ($BAK_2).\033[0m"
echo
exit
fi
}

@@ -130,14 +129,13 @@ CHK_BAK3 (){
if [[ $? == 0 ]]; then
echo -e " \033[34mPass. \033[0m"
else
echo -e " \033[31mFail. Exit.\033[0m"
echo -e " \033[33mWarning! There is no local backup file ($BAK_3).\033[0m"
echo
exit
fi
}

MKDIR_REMOTE_BAK_Folder_BAK_Disk_X (){
echo -e "\033[32mmkdir Remote Backup folder alwyass ($ID@$IP:$Remote_BAK_Folder_BAK_Disk_X) \033[0m"
echo -e "\033[32mmkdir Remote Backup folder always ($ID@$IP:$Remote_BAK_Folder_BAK_Disk_X) \033[0m"
expect -c "
spawn ssh $ID@$IP \"mkdir -p $Remote_BAK_Folder_BAK_Disk_X;\"
expect {
@@ -148,7 +146,7 @@ MKDIR_REMOTE_BAK_Folder_BAK_Disk_X (){
}

MKDIR_REMOTE_BAK_Folder_BAK_Disk_Y (){
echo -e "\033[32mmkdir Remote Backup folder alwyass ($ID@$IP:$Remote_BAK_Folder_BAK_Disk_Y) \033[0m"
echo -e "\033[32mmkdir Remote Backup folder always ($ID@$IP:$Remote_BAK_Folder_BAK_Disk_Y) \033[0m"
expect -c "
spawn ssh $ID@$IP \"mkdir -p $Remote_BAK_Folder_BAK_Disk_Y;\"
expect {
@@ -220,9 +218,9 @@ CHK_REMOTE_IP_AVA
CHK_BAK1
CHK_BAK2
CHK_BAK3
#MKDIR_REMOTE_BAK_Folder_BAK_Disk_X
#MKDIR_REMOTE_BAK_Folder_BAK_Disk_X; wait
#SCP_TO_BAK_Disk_X
#MKDIR_REMOTE_BAK_Folder_BAK_Disk_Y
#MKDIR_REMOTE_BAK_Folder_BAK_Disk_Y; wait
#SCP_TO_BAK_Disk_Y



+ 6
- 5
ED8Remote_backup.sh.SRC Переглянути файл

@@ -12,7 +12,8 @@ fi

BAK_Project=ED8
WHO=`whoami`
HOSTNAME=`hostnamectl | grep "Static hostname" | awk '{print $NF}'`
#HOSTNAME=`hostnamectl | grep "Static hostname" | awk '{print $NF}'`
HOSTNAME=`hostname`
TS=`date +"%Y%m%d-%H%M%S"`

# Host Local Backup info setup
@@ -134,7 +135,7 @@ CHK_BAK3 (){
}

MKDIR_REMOTE_BAK_Folder_BAK_Disk_X (){
echo -e "\033[32mmkdir Remote Backup folder alwyass ($ID@$IP:$Remote_BAK_Folder_BAK_Disk_X) \033[0m"
echo -e "\033[32mmkdir Remote Backup folder always ($ID@$IP:$Remote_BAK_Folder_BAK_Disk_X) \033[0m"
expect -c "
spawn ssh $ID@$IP \"mkdir -p $Remote_BAK_Folder_BAK_Disk_X;\"
expect {
@@ -145,7 +146,7 @@ MKDIR_REMOTE_BAK_Folder_BAK_Disk_X (){
}

MKDIR_REMOTE_BAK_Folder_BAK_Disk_Y (){
echo -e "\033[32mmkdir Remote Backup folder alwyass ($ID@$IP:$Remote_BAK_Folder_BAK_Disk_Y) \033[0m"
echo -e "\033[32mmkdir Remote Backup folder always ($ID@$IP:$Remote_BAK_Folder_BAK_Disk_Y) \033[0m"
expect -c "
spawn ssh $ID@$IP \"mkdir -p $Remote_BAK_Folder_BAK_Disk_Y;\"
expect {
@@ -217,9 +218,9 @@ CHK_REMOTE_IP_AVA
CHK_BAK1
CHK_BAK2
CHK_BAK3
#MKDIR_REMOTE_BAK_Folder_BAK_Disk_X
#MKDIR_REMOTE_BAK_Folder_BAK_Disk_X; wait
#SCP_TO_BAK_Disk_X
#MKDIR_REMOTE_BAK_Folder_BAK_Disk_Y
#MKDIR_REMOTE_BAK_Folder_BAK_Disk_Y; wait
#SCP_TO_BAK_Disk_Y



+ 2
- 2
ED8backup-Script_ED8-Auto.sh.SRC Переглянути файл

@@ -81,8 +81,8 @@ echo -e "\033[32mStart backup the Script_${BAK_Project} \033[0m" | tee -a $LOG1
CHK_LOG_Folder | tee -a $LOG1
CHK_Bak_Folder | tee -a $LOG1
TAR_File | tee -a $LOG1
#CP_TO_BAK_Disk_A | tee -a $LOG1
#CP_TO_BAK_Disk_B | tee -a $LOG1
CP_TO_BAK_Disk_A | tee -a $LOG1
CP_TO_BAK_Disk_B | tee -a $LOG1

echo | tee -a $LOG1


+ 2
- 2
ED8backup-Source_Files-Auto.sh.SRC Переглянути файл

@@ -81,8 +81,8 @@ echo -e "\033[32mStart backup the ${BAK_Project} Source_Files \033[0m" | tee -a
CHK_LOG_Folder | tee -a $LOG1
CHK_Bak_Folder | tee -a $LOG1
TAR_File | tee -a $LOG1
#CP_TO_BAK_Disk_A | tee -a $LOG1
#CP_TO_BAK_Disk_B | tee -a $LOG1
CP_TO_BAK_Disk_A | tee -a $LOG1
CP_TO_BAK_Disk_B | tee -a $LOG1

echo | tee -a $LOG1


+ 58
- 0
ED8backup-attachment-Auto.sh Переглянути файл

@@ -0,0 +1,58 @@
#!/bin/bash
BAK_Project=ED8
USER=`whoami`
TS=`date +"%Y%m%d-%H%M%S"`
LOG_Folder="/ED/${BAK_Project}/Script_${BAK_Project}/_LOG"
LOG1=/ED/${BAK_Project}/Script_${BAK_Project}/_LOG/${BAK_Project}backup-attachment-Auto.log
Bak_Folder="/ED/${BAK_Project}/Backup_file"
Bak_File_Name=$Bak_Folder/backup-attachment-${BAK_Project}.tar.gz
Bak_File_Name_TS=$Bak_Folder/backup-attachment-${BAK_Project}-$TS.tar.gz

CHK_LOG_Folder (){
echo -e "\033[32mCheck the auto backup log saving folder exist: \033[35m($LOG_Folder) \033[0m"
ls $LOG_Folder > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e " >> \033[33mWarning! There is no folder \"$LOG_Folder\". Next will create a new one.\033[0m" | tee -a $LOG1
sudo mkdir -p $LOG_Folder
sudo chown $USER:$USER $LOG_Folder -R
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
else echo -e " >> \033[34mPass. There is a folder \"$LOG_Folder\". \033[0m" | tee -a $LOG1
fi
}

CHK_Bak_Folder (){
echo -e "\033[32mCheck the local original backup folder exist: \033[35m($Bak_Folder) \033[0m"
ls $Bak_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Backup file saving folder: $Bak_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no Backup file saving folder: $Bak_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $Bak_Folder
sudo chown $USER:$USER $Bak_Folder -R
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

TAR_ATTACHMENT (){
echo -e "\033[32mStarting tar Forum attachment...\033[0m"
echo -e "\033[45;37m==========================================================================================\033[0m" | tee -a $LOG1
tar -zcvf $Bak_File_Name /var/www/html/ed8/data
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. tar files OK" | tee -a $LOG1; else echo -e " >> \033[34mFail. tar files Failed"; fi

echo -e "\033[32mStarting make a copy with timastamp filename...\033[0m" | tee -a $LOG1
cp $Bak_File_Name $Bak_File_Name_TS
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Make a copy OK - \033[35m($Bak_File_Name_TS) \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m($Bak_File_Name_TS) \033[0m" | tee -a $LOG1; echo; exit
fi
}


##### Main
echo -e "===== `date +"%Y/%m/%d %H:%M:%S"` ===== \033[45;37m$0\033[0m =====" | tee -a $LOG1
CHK_LOG_Folder
CHK_Bak_Folder
TAR_ATTACHMENT

echo
echo -e "\033[33mIf you want to check the LOG, please perform below command: "
echo -e " # cat $LOG1\033[0m"
echo

+ 58
- 0
ED8backup-attachment-Auto.sh.SRC Переглянути файл

@@ -0,0 +1,58 @@
#!/bin/bash
BAK_Project=ED8
USER=`whoami`
TS=`date +"%Y%m%d-%H%M%S"`
LOG_Folder="/ED/${BAK_Project}/Script_${BAK_Project}/_LOG"
LOG1=/ED/${BAK_Project}/Script_${BAK_Project}/_LOG/${BAK_Project}backup-attachment-Auto.log
Bak_Folder="/ED/${BAK_Project}/Backup_file"
Bak_File_Name=$Bak_Folder/backup-attachment-${BAK_Project}.tar.gz
Bak_File_Name_TS=$Bak_Folder/backup-attachment-${BAK_Project}-$TS.tar.gz

CHK_LOG_Folder (){
echo -e "\033[32mCheck the auto backup log saving folder exist: \033[35m($LOG_Folder) \033[0m"
ls $LOG_Folder > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e " >> \033[33mWarning! There is no folder \"$LOG_Folder\". Next will create a new one.\033[0m" | tee -a $LOG1
sudo mkdir -p $LOG_Folder
sudo chown $USER:$USER $LOG_Folder -R
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
else echo -e " >> \033[34mPass. There is a folder \"$LOG_Folder\". \033[0m" | tee -a $LOG1
fi
}

CHK_Bak_Folder (){
echo -e "\033[32mCheck the local original backup folder exist: \033[35m($Bak_Folder) \033[0m"
ls $Bak_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Backup file saving folder: $Bak_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no Backup file saving folder: $Bak_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $Bak_Folder
sudo chown $USER:$USER $Bak_Folder -R
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

TAR_ATTACHMENT (){
echo -e "\033[32mStarting tar Forum attachment...\033[0m"
echo -e "\033[45;37m==========================================================================================\033[0m" | tee -a $LOG1
tar -zcvf $Bak_File_Name /var/www/html/ed8/data
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. tar files OK" | tee -a $LOG1; else echo -e " >> \033[34mFail. tar files Failed"; fi

echo -e "\033[32mStarting make a copy with timastamp filename...\033[0m" | tee -a $LOG1
cp $Bak_File_Name $Bak_File_Name_TS
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Make a copy OK - \033[35m($Bak_File_Name_TS) \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m($Bak_File_Name_TS) \033[0m" | tee -a $LOG1; echo; exit
fi
}


##### Main
echo -e "===== `date +"%Y/%m/%d %H:%M:%S"` ===== \033[45;37m$0\033[0m =====" | tee -a $LOG1
CHK_LOG_Folder
CHK_Bak_Folder
TAR_ATTACHMENT

echo
echo -e "\033[33mIf you want to check the LOG, please perform below command: "
echo -e " # cat $LOG1\033[0m"
echo

+ 47
- 0
ED8backup-attachment-rsync-Auto.sh Переглянути файл

@@ -0,0 +1,47 @@
#!/bin/bash
BAK_Project=ED8
USER=`whoami`
LOG_Folder="/ED/${BAK_Project}/Script_${BAK_Project}/_LOG"
LOG1=/ED/${BAK_Project}/Script_${BAK_Project}/_LOG/${BAK_Project}backup-attachment-rsync-Auto.log
Bak_Folder="/ED/${BAK_Project}/Backup_file"
ATTACH_FILE_Folder="/var/www/html/ed8/data"

CHK_LOG_Folder (){
echo -e "\033[32mCheck the auto backup log saving folder exist: \033[35m($LOG_Folder) \033[0m" | tee -a $LOG1
ls $LOG_Folder > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e " >> \033[33mWarning! There is no folder \"$LOG_Folder\". Next will create a new one.\033[0m" | tee -a $LOG1
sudo mkdir -p $LOG_Folder
sudo chown $USER:$USER $LOG_Folder -R
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m" | tee -a $LOG1; echo; exit; fi
else echo -e " >> \033[34mPass. There is a folder \"$LOG_Folder\". \033[0m" | tee -a $LOG1
fi
}

CHK_Bak_Folder (){
echo -e "\033[32mCheck the local original backup folder exist: \033[35m($Bak_Folder) \033[0m" | tee -a $LOG1
ls $Bak_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Backup file saving folder: $Bak_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no Backup file saving folder: $Bak_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $Bak_Folder
sudo chown $USER:$USER $Bak_Folder -R
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m" | tee -a $LOG1; echo; exit; fi
fi
}

RSYNC_ATTACHMENT (){
echo -e "\033[32mStarting rsync... \033[0m" | tee -a $LOG1
rsync -a $ATTACH_FILE_Folder $Bak_Folder/
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. rsync attach file directory ($ATTACH_FILE_Folder).\033[0m" | tee -a $LOG1;
else echo -e " >> \033[31mFail. rsync attach file directory ($ATTACH_FILE_Folder) failed.\033[0m" | tee -a $LOG1
fi; echo

}

##### Main
echo -e "===== \033[43;30m$(date +"%Y/%m/%d %H:%M:%S")\033[0m ===== \033[36m$0\033[0m =====" | tee -a $LOG1
CHK_LOG_Folder
CHK_Bak_Folder
RSYNC_ATTACHMENT


+ 47
- 0
ED8backup-attachment-rsync-Auto.sh.SRC Переглянути файл

@@ -0,0 +1,47 @@
#!/bin/bash
BAK_Project=ED8
USER=`whoami`
LOG_Folder="/ED/${BAK_Project}/Script_${BAK_Project}/_LOG"
LOG1=/ED/${BAK_Project}/Script_${BAK_Project}/_LOG/${BAK_Project}backup-attachment-rsync-Auto.log
Bak_Folder="/ED/${BAK_Project}/Backup_file"
ATTACH_FILE_Folder="/var/www/html/ed8/data"

CHK_LOG_Folder (){
echo -e "\033[32mCheck the auto backup log saving folder exist: \033[35m($LOG_Folder) \033[0m" | tee -a $LOG1
ls $LOG_Folder > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e " >> \033[33mWarning! There is no folder \"$LOG_Folder\". Next will create a new one.\033[0m" | tee -a $LOG1
sudo mkdir -p $LOG_Folder
sudo chown $USER:$USER $LOG_Folder -R
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m" | tee -a $LOG1; echo; exit; fi
else echo -e " >> \033[34mPass. There is a folder \"$LOG_Folder\". \033[0m" | tee -a $LOG1
fi
}

CHK_Bak_Folder (){
echo -e "\033[32mCheck the local original backup folder exist: \033[35m($Bak_Folder) \033[0m" | tee -a $LOG1
ls $Bak_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Backup file saving folder: $Bak_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no Backup file saving folder: $Bak_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $Bak_Folder
sudo chown $USER:$USER $Bak_Folder -R
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m" | tee -a $LOG1; echo; exit; fi
fi
}

RSYNC_ATTACHMENT (){
echo -e "\033[32mStarting rsync... \033[0m" | tee -a $LOG1
rsync -a $ATTACH_FILE_Folder $Bak_Folder/
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. rsync attach file directory ($ATTACH_FILE_Folder).\033[0m" | tee -a $LOG1;
else echo -e " >> \033[31mFail. rsync attach file directory ($ATTACH_FILE_Folder) failed.\033[0m" | tee -a $LOG1
fi; echo

}

##### Main
echo -e "===== \033[43;30m$(date +"%Y/%m/%d %H:%M:%S")\033[0m ===== \033[36m$0\033[0m =====" | tee -a $LOG1
CHK_LOG_Folder
CHK_Bak_Folder
RSYNC_ATTACHMENT


+ 57
- 161
ED8backup-mysql-Auto.sh Переглянути файл

@@ -32,42 +32,25 @@ BAK_Disk_B_Bak_File_Name_TS="$BAK_Disk_B_BAK_Folder/backup-mysql-${BAK_Project}-
CHK_PWFile (){
echo -e "\033[32mCheck the mysql password info file exist: \033[0m"
ls $PWFile > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e " >> \033[31mFail. $PWFile didn't exist. Please create one. Exit\033[0m" | tee -a $LOG1
echo
if [[ $? != 0 ]]; then echo -e " >> \033[31mFail. $PWFile didn't exist. Please create one. Exit\033[0m" | tee -a $LOG1; echo
echo -e "$PWFile Content example: "
echo -e "Database_Name: db_ed8_"
echo -e "ID: ed"
echo -e "Password: +039*******"
echo
exit
else
echo -e " >> \033[34mPass. $PWFile exist.\033[0m" | tee -a $LOG1
echo -e "Password: +039*******"; echo; exit
else echo -e " >> \033[34mPass. $PWFile exist.\033[0m" | tee -a $LOG1
echo -e -n " Check context information accuracy (DATABASEName)\t\t: "
if [[ $DATABASEName == "" ]]; then
echo -e "\033[31mFail. There is no correct info of DATABASEName in $PWFile. Exit\033[0m"
echo
exit
else
echo -e "\033[34mPass. \033[0m"
if [[ $DATABASEName == "" ]]; then echo -e "\033[31mFail. There is no correct info of DATABASEName in $PWFile. Exit\033[0m"; echo; exit
else echo -e "\033[34mPass. \033[0m"
fi

echo -e -n " Check context information accuracy (DATABASEUser)\t\t: "
if [[ $DATABASEUser == "" ]]; then
echo -e "\033[31mFail. There is no correct info of DATABASEUser in $PWFile. Exit\033[0m"
echo
exit
else
echo -e "\033[34mPass. \033[0m"
if [[ $DATABASEUser == "" ]]; then echo -e "\033[31mFail. There is no correct info of DATABASEUser in $PWFile. Exit\033[0m"; echo; exit
else echo -e "\033[34mPass. \033[0m"
fi

echo -e -n " Check context information accuracy (DATABASEPassword)\t: "
if [[ $DATABASEPassword == "" ]]; then
echo -e "\033[31mFail. There is no correct info of DATABASEPassword in $PWFile. Exit\033[0m"
echo
exit
else
echo -e "\033[34mPass. \033[0m"
if [[ $DATABASEPassword == "" ]]; then echo -e "\033[31mFail. There is no correct info of DATABASEPassword in $PWFile. Exit\033[0m"; echo; exit
else echo -e "\033[34mPass. \033[0m"
fi
fi
}
@@ -75,126 +58,81 @@ CHK_PWFile (){
CHK_LOG_Folder (){
echo -e "\033[32mCheck the auto backup log saving folder exist: \033[35m($LOG_Folder) \033[0m"
ls $LOG_Folder > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e " >> \033[33mWarning! There is no folder \"$LOG_Folder\". Next will create a new one.\033[0m" | tee -a $LOG1
if [[ $? != 0 ]]; then echo -e " >> \033[33mWarning! There is no folder \"$LOG_Folder\". Next will create a new one.\033[0m" | tee -a $LOG1
sudo mkdir -p $LOG_Folder
sudo chown $USER:$USER $LOG_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
else
echo -e " >> \033[34mPass. There is a folder \"$LOG_Folder\". \033[0m" | tee -a $LOG1
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
else echo -e " >> \033[34mPass. There is a folder \"$LOG_Folder\". \033[0m" | tee -a $LOG1
fi
}

CHK_Bak_Folder (){
echo -e "\033[32mCheck the local original backup folder exist: \033[35m($Bak_Folder) \033[0m"
ls $Bak_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. Backup file saving folder: $Bak_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no Backup file saving folder: $Bak_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Backup file saving folder: $Bak_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! There is no Backup file saving folder: $Bak_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $Bak_Folder
sudo chown $USER:$USER $Bak_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

Mysql_Dump (){
echo -e "\033[32mStarting mysqldump...\033[0m"
echo -e "\033[45;37m==========================================================================================\033[0m" | tee -a $LOG1
echo -e "\033[41;37m Important! Please check below messages for making sure mysqldump be performed exactly. \033[0m" | tee -a $LOG1
echo -e " \033[41;37mImportant! Please check below messages for making sure mysqldump be performed exactly. \033[0m" | tee -a $LOG1
mysqldump -u $DATABASEUser -p$DATABASEPassword $DATABASEName | gzip > $Bak_File_Name
# mysqldump -u $DATABASEUser -p$DATABASEPassword $DATABASEName | gzip > $Bak_File_Name
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. mysql dump w/ gzip OK. \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37m Fail. mysql dump w/ gzip failed. Exit \033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. mysql dump w/ gzip OK. \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37m Fail. mysql dump w/ gzip failed. Exit \033[0m" | tee -a $LOG1
echo -e " >> \033[31m If you got error message, please try to perform below command for debugging\033[0m" | tee -a $LOG1
echo -e " >> \033[31m # sudo mysqldump -u ed -p db_ed8_ | gzip > $Bak_File_Name \033[0m" | tee -a $LOG1
echo
exit
echo -e " >> \033[31m # sudo mysqldump -u ed -p db_ed8_ | gzip > $Bak_File_Name \033[0m" | tee -a $LOG1; echo; exit
fi
echo -e "\033[45;37m==========================================================================================\033[0m" | tee -a $LOG1
echo -e " Debug message: "
echo -e " \033[32m* mysqldump: Got error: 1045: Access denied for user 'ed'@'localhost' (using password: YES) when trying to connect \033[0m "
echo -e " \033[46;30m----- Debug message ---------------\033[0m" | tee -a $LOG1
echo -e " \033[32m* If mysqldump: Got error: 1045: Access denied for user 'ed'@'localhost' (using password: YES) when trying to connect \033[0m "
echo -e " >> Please check the content of $PWFile"
echo -e "\033[45;37m==========================================================================================\033[0m"

echo -e "\033[32mStarting make a copy with timastamp filename...\033[0m" | tee -a $LOG1
cp $Bak_File_Name $Bak_File_Name_TS
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. Make a copy OK - \033[35m($Bak_File_Name_TS) \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m($Bak_File_Name_TS) \033[0m" | tee -a $LOG1
echo
exit
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Make a copy OK - \033[35m$Bak_File_Name_TS \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m$Bak_File_Name_TS \033[0m" | tee -a $LOG1; echo; exit
fi
}

CHK_BAK_Disk_A (){
echo -e "\033[32mCheck the detection of Backup_Disk_A: \033[35m(lsscsi $BAK_Disk_A) \033[0m"
lsscsi | grep $BAK_Disk_A > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. The BAK_Disk_A \"$BAK_Disk_A\" be detected by lsscsi. \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. The BAK_Disk_A \"$BAK_Disk_A\" not be detected by lsscsi. Exit \033[0m" | tee -a $LOG1
echo
exit
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. The BAK_Disk_A \"$BAK_Disk_A\" be detected by lsscsi. \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. The BAK_Disk_A \"$BAK_Disk_A\" not be detected by lsscsi. Exit \033[0m" | tee -a $LOG1; echo; exit
fi
}

CHK_BAK_Disk_B (){
echo -e "\033[32mCheck the detection of Backup_Disk_A: \033[35m(lsscsi $BAK_Disk_B) \033[0m"
lsscsi | grep $BAK_Disk_B > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. The BAK_Disk_B \"$BAK_Disk_B\" be detected by lsscsi. \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. The BAK_Disk_B \"$BAK_Disk_B\" not be detected by lsscsi. Exit \033[0m" | tee -a $LOG1
echo
exit
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. The BAK_Disk_B \"$BAK_Disk_B\" be detected by lsscsi. \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. The BAK_Disk_B \"$BAK_Disk_B\" not be detected by lsscsi. Exit \033[0m" | tee -a $LOG1; echo; exit
fi
}

CHK_BAK_Disk_A_Mount_Point (){
echo -e "\033[32mCheck the BAK_Disk_A mount point folder exist: \033[35m($BAK_Disk_A_Mount_Point) \033[0m"
ls $BAK_Disk_A_Mount_Point > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. The BAK_Disk_A mount point exist \"$BAK_Disk_A_Mount_Point\"\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! The BAK_Disk_A mount point doesn't exist \"$BAK_Disk_A_Mount_Point\"\033[0m, auto create a new one. " | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. The BAK_Disk_A mount point exist \"$BAK_Disk_A_Mount_Point\"\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! The BAK_Disk_A mount point doesn't exist \"$BAK_Disk_A_Mount_Point\"\033[0m, auto create a new one. " | tee -a $LOG1
sudo mkdir -p $BAK_Disk_A_Mount_Point
sudo chown $USER:$USER $BAK_Disk_A_Mount_Point -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi

if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CHK_BAK_Disk_B_Mount_Point (){
echo -e "\033[32mCheck the BAK_Disk_A mount point folder exist: \033[35m($BAK_Disk_B_Mount_Point) \033[0m"
ls $BAK_Disk_B_Mount_Point > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. The BAK_Disk_B mount point exist \"$BAK_Disk_B_Mount_Point\"\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! The BAK_Disk_B mount point doesn't exist \"$BAK_Disk_B_Mount_Point\"\033[0m, auto create a new one. " | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. The BAK_Disk_B mount point exist \"$BAK_Disk_B_Mount_Point\"\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! The BAK_Disk_B mount point doesn't exist \"$BAK_Disk_B_Mount_Point\"\033[0m, auto create a new one. " | tee -a $LOG1
sudo mkdir -p $BAK_Disk_B_Mount_Point
sudo chown $USER:$USER $BAK_Disk_B_Mount_Point -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi

if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

@@ -202,11 +140,8 @@ CHK_BAK_Disk_A_Mount_Status (){
echo -e "\033[32mCheck the BAK_Disk_A mount status: \033[0m"
if [[ `df -h | grep $BAK_Disk_A | awk '{print $NF}'` != $BAK_Disk_A_Mount_Point ]]; then
echo -e " >> \033[31mFail. The BAK_Disk_A ($BAK_Disk_A) not be mounted at \"$BAK_Disk_A_Mount_Point\". Exit. \033[0m" | tee -a $LOG1
df -h
echo
exit
else
echo -e " >> \033[34mPass. The BAK_Disk_A ($BAK_Disk_A) be mounted at \"$BAK_Disk_A_Mount_Point\"\033[0m" | tee -a $LOG1
df -h; echo; exit
else echo -e " >> \033[34mPass. The BAK_Disk_A ($BAK_Disk_A) be mounted at \"$BAK_Disk_A_Mount_Point\"\033[0m" | tee -a $LOG1
fi
}

@@ -214,116 +149,78 @@ CHK_BAK_Disk_B_Mount_Status (){
echo -e "\033[32mCheck the BAK_Disk_B mount status: \033[0m"
if [[ `df -h | grep $BAK_Disk_B | awk '{print $NF}'` != $BAK_Disk_B_Mount_Point ]]; then
echo -e " >> \033[31mFail. The BAK_Disk_B ($BAK_Disk_B) not be mounted at \"$BAK_Disk_B_Mount_Point\". Exit. \033[0m" | tee -a $LOG1
df -h
echo
exit
else
echo -e " >> \033[34mPass. The BAK_Disk_B ($BAK_Disk_B) be mounted at \"$BAK_Disk_B_Mount_Point\"\033[0m" | tee -a $LOG1
df -h; echo; exit
else echo -e " >> \033[34mPass. The BAK_Disk_B ($BAK_Disk_B) be mounted at \"$BAK_Disk_B_Mount_Point\"\033[0m" | tee -a $LOG1
fi
}

CHK_BAK_Disk_A_Hostname_Folder (){
echo -e "\033[32mCheck the BAK_Disk_A Hostname folder status: \033[35m($BAK_Disk_A_Hostname_Folder) \033[0m"
ls $BAK_Disk_A_Hostname_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. BAK_Disk_A Hostname folder: $BAK_Disk_A_Hostname_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! BAK_Disk_A Hostname folder: $BAK_Disk_A_Hostname_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. BAK_Disk_A Hostname folder: $BAK_Disk_A_Hostname_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! BAK_Disk_A Hostname folder: $BAK_Disk_A_Hostname_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sduo mkdir -p $BAK_Disk_A_Hostname_Folder
sudo chown $USER:$USER $BAK_Disk_A_Hostname_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CHK_BAK_Disk_B_Hostname_Folder (){
echo -e "\033[32mCheck the BAK_Disk_B Hostname folder status: \033[35m($BAK_Disk_B_Hostname_Folder) \033[0m"
ls $BAK_Disk_B_Hostname_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. BAK_Disk_B Hostname folder: $BAK_Disk_B_Hostname_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[31mWarning! BAK_Disk_B Hostname folder: $BAK_Disk_B_Hostname_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. BAK_Disk_B Hostname folder: $BAK_Disk_B_Hostname_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[31mWarning! BAK_Disk_B Hostname folder: $BAK_Disk_B_Hostname_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $BAK_Disk_B_Hostname_Folder
sudo chown $USER:$USER $BAK_Disk_B_Hostname_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CHK_BAK_Disk_A_BAK_Folder (){
echo -e "\033[32mCheck the BAK_Disk_A ${BAK_Project} backup folder status: \033[35m($BAK_Disk_A_BAK_Folder) \033[0m"
ls $BAK_Disk_A_BAK_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. BAK_Disk's Backup file saving folder: $BAK_Disk_A_BAK_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no BAK_Disk's Backup file saving folder: $BAK_Disk_A_BAK_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. BAK_Disk's Backup file saving folder: $BAK_Disk_A_BAK_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! There is no BAK_Disk's Backup file saving folder: $BAK_Disk_A_BAK_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $BAK_Disk_A_BAK_Folder
sudo chown $USER:$USER $BAK_Disk_A_BAK_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CHK_BAK_Disk_B_BAK_Folder (){
echo -e "\033[32mCheck the BAK_Disk_B ${BAK_Project} backup folder status: \033[35m($BAK_Disk_B_BAK_Folder) \033[0m"
ls $BAK_Disk_B_BAK_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. BAK_Disk's Backup file saving folder: $BAK_Disk_B_BAK_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no BAK_Disk's Backup file saving folder: $BAK_Disk_B_BAK_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. BAK_Disk's Backup file saving folder: $BAK_Disk_B_BAK_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! There is no BAK_Disk's Backup file saving folder: $BAK_Disk_B_BAK_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $BAK_Disk_B_BAK_Folder
sudo chown $USER:$USER $BAK_Disk_B_BAK_Folder -R

if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CP_TO_BAK_Disk_A (){
echo -e "\033[32mCopy the backup files to Backup_Disk_A...\033[0m"
cp $Bak_File_Name_TS $BAK_Disk_A_Bak_File_Name_TS
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. Make a copy OK - \033[35m($BAK_Disk_A_Bak_File_Name_TS) \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m($BAK_Disk_A_Bak_File_Name_TS) \033[0m" | tee -a $LOG1
echo
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Make a copy OK - \033[35m$BAK_Disk_A_Bak_File_Name_TS \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m$BAK_Disk_A_Bak_File_Name_TS \033[0m" | tee -a $LOG1; echo
echo -e " \033[35mIf you got (Permission denied) message, please perform below command and re-do again. \033[0m"
echo -e " \033[35mIt happened at fist backup, caused from created disk mount point folder ($BAK_Disk_A_Mount_Point) with sudo \033[0m"
echo -e " \033[41;37m# sudo chown $USER:$USER $BAK_Disk_A_Mount_Point \033[0m"
echo
exit
echo -e " \033[41;37m# sudo chown $USER:$USER $BAK_Disk_A_Mount_Point \033[0m"; echo; exit
fi
}

CP_TO_BAK_Disk_B (){
echo -e "\033[32mCopy the backup files to Backup_Disk_B...\033[0m"
cp $Bak_File_Name_TS $BAK_Disk_B_Bak_File_Name_TS
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. Make a copy OK - \033[35m($BAK_Disk_B_Bak_File_Name_TS) \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m($BAK_Disk_B_Bak_File_Name_TS) \033[0m" | tee -a $LOG1
echo
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Make a copy OK - \033[35m$BAK_Disk_B_Bak_File_Name_TS \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m$BAK_Disk_B_Bak_File_Name_TS \033[0m" | tee -a $LOG1; echo
echo -e " \033[35mIf you got (Permission denied) message, please perform below command and re-do again. \033[0m"
echo -e " \033[35mIt happened at fist backup, caused from created disk mount point folder ($BAK_Disk_B_Mount_Point) with sudo \033[0m"
echo -e " \033[41;37m# sudo chown $USER:$USER $BAK_Disk_B_Mount_Point \033[0m"
echo
exit
echo -e " \033[41;37m# sudo chown $USER:$USER $BAK_Disk_B_Mount_Point \033[0m"; echo; exit
fi
}

echo -e "===== `date +"%Y/%m/%d %H:%M:%S"` ===== \033[45;37m$0\033[0m =====" | tee -a $LOG1
echo -e "===== \033[43;30m`date +"%Y/%m/%d %H:%M:%S"`\033[0m ===== \033[35m$0\033[0m =====" | tee -a $LOG1
CHK_PWFile
CHK_LOG_Folder
CHK_Bak_Folder
@@ -344,5 +241,4 @@ CP_TO_BAK_Disk_B

echo
echo -e "\033[33mIf you want to check the LOG, please perform below command: "
echo -e " # cat $LOG1\033[0m"
echo
echo -e " # cat $LOG1\033[0m"; echo

+ 70
- 174
ED8backup-mysql-Auto.sh.SRC Переглянути файл

@@ -32,42 +32,25 @@ BAK_Disk_B_Bak_File_Name_TS="$BAK_Disk_B_BAK_Folder/backup-mysql-${BAK_Project}-
CHK_PWFile (){
echo -e "\033[32mCheck the mysql password info file exist: \033[0m"
ls $PWFile > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e " >> \033[31mFail. $PWFile didn't exist. Please create one. Exit\033[0m" | tee -a $LOG1
echo
if [[ $? != 0 ]]; then echo -e " >> \033[31mFail. $PWFile didn't exist. Please create one. Exit\033[0m" | tee -a $LOG1; echo
echo -e "$PWFile Content example: "
echo -e "Database_Name: db_ed8_"
echo -e "ID: ed"
echo -e "Password: +039*******"
echo
exit
else
echo -e " >> \033[34mPass. $PWFile exist.\033[0m" | tee -a $LOG1
echo -e "Password: +039*******"; echo; exit
else echo -e " >> \033[34mPass. $PWFile exist.\033[0m" | tee -a $LOG1
echo -e -n " Check context information accuracy (DATABASEName)\t\t: "
if [[ $DATABASEName == "" ]]; then
echo -e "\033[31mFail. There is no correct info of DATABASEName in $PWFile. Exit\033[0m"
echo
exit
else
echo -e "\033[34mPass. \033[0m"
if [[ $DATABASEName == "" ]]; then echo -e "\033[31mFail. There is no correct info of DATABASEName in $PWFile. Exit\033[0m"; echo; exit
else echo -e "\033[34mPass. \033[0m"
fi

echo -e -n " Check context information accuracy (DATABASEUser)\t\t: "
if [[ $DATABASEUser == "" ]]; then
echo -e "\033[31mFail. There is no correct info of DATABASEUser in $PWFile. Exit\033[0m"
echo
exit
else
echo -e "\033[34mPass. \033[0m"
if [[ $DATABASEUser == "" ]]; then echo -e "\033[31mFail. There is no correct info of DATABASEUser in $PWFile. Exit\033[0m"; echo; exit
else echo -e "\033[34mPass. \033[0m"
fi

echo -e -n " Check context information accuracy (DATABASEPassword)\t: "
if [[ $DATABASEPassword == "" ]]; then
echo -e "\033[31mFail. There is no correct info of DATABASEPassword in $PWFile. Exit\033[0m"
echo
exit
else
echo -e "\033[34mPass. \033[0m"
if [[ $DATABASEPassword == "" ]]; then echo -e "\033[31mFail. There is no correct info of DATABASEPassword in $PWFile. Exit\033[0m"; echo; exit
else echo -e "\033[34mPass. \033[0m"
fi
fi
}
@@ -75,126 +58,81 @@ CHK_PWFile (){
CHK_LOG_Folder (){
echo -e "\033[32mCheck the auto backup log saving folder exist: \033[35m($LOG_Folder) \033[0m"
ls $LOG_Folder > /dev/null 2>&1
if [[ $? != 0 ]]; then
echo -e " >> \033[33mWarning! There is no folder \"$LOG_Folder\". Next will create a new one.\033[0m" | tee -a $LOG1
if [[ $? != 0 ]]; then echo -e " >> \033[33mWarning! There is no folder \"$LOG_Folder\". Next will create a new one.\033[0m" | tee -a $LOG1
sudo mkdir -p $LOG_Folder
sudo chown $USER:$USER $LOG_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
else
echo -e " >> \033[34mPass. There is a folder \"$LOG_Folder\". \033[0m" | tee -a $LOG1
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
else echo -e " >> \033[34mPass. There is a folder \"$LOG_Folder\". \033[0m" | tee -a $LOG1
fi
}

CHK_Bak_Folder (){
echo -e "\033[32mCheck the local original backup folder exist: \033[35m($Bak_Folder) \033[0m"
ls $Bak_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. Backup file saving folder: $Bak_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no Backup file saving folder: $Bak_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Backup file saving folder: $Bak_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! There is no Backup file saving folder: $Bak_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $Bak_Folder
sudo chown $USER:$USER $Bak_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

Mysql_Dump (){
echo -e "\033[32mStarting mysqldump...\033[0m"
echo -e "\033[45;37m==========================================================================================\033[0m" | tee -a $LOG1
echo -e "\033[41;37m Important! Please check below messages for making sure mysqldump be performed exactly. \033[0m" | tee -a $LOG1
/opt/lampp/bin/mysqldump -u $DATABASEUser -p$DATABASEPassword $DATABASEName | gzip > $Bak_File_Name
echo -e " \033[41;37mImportant! Please check below messages for making sure mysqldump be performed exactly. \033[0m" | tee -a $LOG1
mysqldump -u $DATABASEUser -p$DATABASEPassword $DATABASEName | gzip > $Bak_File_Name
# mysqldump -u $DATABASEUser -p$DATABASEPassword $DATABASEName | gzip > $Bak_File_Name
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. mysql dump w/ gzip OK. \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37m Fail. mysql dump w/ gzip failed. Exit \033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. mysql dump w/ gzip OK. \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37m Fail. mysql dump w/ gzip failed. Exit \033[0m" | tee -a $LOG1
echo -e " >> \033[31m If you got error message, please try to perform below command for debugging\033[0m" | tee -a $LOG1
echo -e " >> \033[31m # sudo /opt/lampp/bin/mysqldump -u ed -p db_ed8_ | gzip > $Bak_File_Name \033[0m" | tee -a $LOG1
echo
exit
echo -e " >> \033[31m # sudo mysqldump -u ed -p db_ed8_ | gzip > $Bak_File_Name \033[0m" | tee -a $LOG1; echo; exit
fi
echo -e "\033[45;37m==========================================================================================\033[0m" | tee -a $LOG1
echo -e " Debug message: "
echo -e " \033[32m* mysqldump: Got error: 1045: Access denied for user 'ed'@'localhost' (using password: YES) when trying to connect \033[0m "
echo -e " \033[46;30m----- Debug message ---------------\033[0m" | tee -a $LOG1
echo -e " \033[32m* If mysqldump: Got error: 1045: Access denied for user 'ed'@'localhost' (using password: YES) when trying to connect \033[0m "
echo -e " >> Please check the content of $PWFile"
echo -e "\033[45;37m==========================================================================================\033[0m"

echo -e "\033[32mStarting make a copy with timastamp filename...\033[0m" | tee -a $LOG1
cp $Bak_File_Name $Bak_File_Name_TS
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. Make a copy OK - \033[35m($Bak_File_Name_TS) \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m($Bak_File_Name_TS) \033[0m" | tee -a $LOG1
echo
exit
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Make a copy OK - \033[35m$Bak_File_Name_TS \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m$Bak_File_Name_TS \033[0m" | tee -a $LOG1; echo; exit
fi
}

CHK_BAK_Disk_A (){
echo -e "\033[32mCheck the detection of Backup_Disk_A: \033[35m(lsscsi $BAK_Disk_A) \033[0m"
lsscsi | grep $BAK_Disk_A > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. The BAK_Disk_A \"$BAK_Disk_A\" be detected by lsscsi. \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. The BAK_Disk_A \"$BAK_Disk_A\" not be detected by lsscsi. Exit \033[0m" | tee -a $LOG1
echo
exit
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. The BAK_Disk_A \"$BAK_Disk_A\" be detected by lsscsi. \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. The BAK_Disk_A \"$BAK_Disk_A\" not be detected by lsscsi. Exit \033[0m" | tee -a $LOG1; echo; exit
fi
}

CHK_BAK_Disk_B (){
echo -e "\033[32mCheck the detection of Backup_Disk_A: \033[35m(lsscsi $BAK_Disk_B) \033[0m"
lsscsi | grep $BAK_Disk_B > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. The BAK_Disk_B \"$BAK_Disk_B\" be detected by lsscsi. \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. The BAK_Disk_B \"$BAK_Disk_B\" not be detected by lsscsi. Exit \033[0m" | tee -a $LOG1
echo
exit
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. The BAK_Disk_B \"$BAK_Disk_B\" be detected by lsscsi. \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. The BAK_Disk_B \"$BAK_Disk_B\" not be detected by lsscsi. Exit \033[0m" | tee -a $LOG1; echo; exit
fi
}

CHK_BAK_Disk_A_Mount_Point (){
echo -e "\033[32mCheck the BAK_Disk_A mount point folder exist: \033[35m($BAK_Disk_A_Mount_Point) \033[0m"
ls $BAK_Disk_A_Mount_Point > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. The BAK_Disk_A mount point exist \"$BAK_Disk_A_Mount_Point\"\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! The BAK_Disk_A mount point doesn't exist \"$BAK_Disk_A_Mount_Point\"\033[0m, auto create a new one. " | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. The BAK_Disk_A mount point exist \"$BAK_Disk_A_Mount_Point\"\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! The BAK_Disk_A mount point doesn't exist \"$BAK_Disk_A_Mount_Point\"\033[0m, auto create a new one. " | tee -a $LOG1
sudo mkdir -p $BAK_Disk_A_Mount_Point
sudo chown $USER:$USER $BAK_Disk_A_Mount_Point -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi

if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CHK_BAK_Disk_B_Mount_Point (){
echo -e "\033[32mCheck the BAK_Disk_A mount point folder exist: \033[35m($BAK_Disk_B_Mount_Point) \033[0m"
ls $BAK_Disk_B_Mount_Point > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. The BAK_Disk_B mount point exist \"$BAK_Disk_B_Mount_Point\"\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! The BAK_Disk_B mount point doesn't exist \"$BAK_Disk_B_Mount_Point\"\033[0m, auto create a new one. " | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. The BAK_Disk_B mount point exist \"$BAK_Disk_B_Mount_Point\"\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! The BAK_Disk_B mount point doesn't exist \"$BAK_Disk_B_Mount_Point\"\033[0m, auto create a new one. " | tee -a $LOG1
sudo mkdir -p $BAK_Disk_B_Mount_Point
sudo chown $USER:$USER $BAK_Disk_B_Mount_Point -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi

if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

@@ -202,11 +140,8 @@ CHK_BAK_Disk_A_Mount_Status (){
echo -e "\033[32mCheck the BAK_Disk_A mount status: \033[0m"
if [[ `df -h | grep $BAK_Disk_A | awk '{print $NF}'` != $BAK_Disk_A_Mount_Point ]]; then
echo -e " >> \033[31mFail. The BAK_Disk_A ($BAK_Disk_A) not be mounted at \"$BAK_Disk_A_Mount_Point\". Exit. \033[0m" | tee -a $LOG1
df -h
echo
exit
else
echo -e " >> \033[34mPass. The BAK_Disk_A ($BAK_Disk_A) be mounted at \"$BAK_Disk_A_Mount_Point\"\033[0m" | tee -a $LOG1
df -h; echo; exit
else echo -e " >> \033[34mPass. The BAK_Disk_A ($BAK_Disk_A) be mounted at \"$BAK_Disk_A_Mount_Point\"\033[0m" | tee -a $LOG1
fi
}

@@ -214,135 +149,96 @@ CHK_BAK_Disk_B_Mount_Status (){
echo -e "\033[32mCheck the BAK_Disk_B mount status: \033[0m"
if [[ `df -h | grep $BAK_Disk_B | awk '{print $NF}'` != $BAK_Disk_B_Mount_Point ]]; then
echo -e " >> \033[31mFail. The BAK_Disk_B ($BAK_Disk_B) not be mounted at \"$BAK_Disk_B_Mount_Point\". Exit. \033[0m" | tee -a $LOG1
df -h
echo
exit
else
echo -e " >> \033[34mPass. The BAK_Disk_B ($BAK_Disk_B) be mounted at \"$BAK_Disk_B_Mount_Point\"\033[0m" | tee -a $LOG1
df -h; echo; exit
else echo -e " >> \033[34mPass. The BAK_Disk_B ($BAK_Disk_B) be mounted at \"$BAK_Disk_B_Mount_Point\"\033[0m" | tee -a $LOG1
fi
}

CHK_BAK_Disk_A_Hostname_Folder (){
echo -e "\033[32mCheck the BAK_Disk_A Hostname folder status: \033[35m($BAK_Disk_A_Hostname_Folder) \033[0m"
ls $BAK_Disk_A_Hostname_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. BAK_Disk_A Hostname folder: $BAK_Disk_A_Hostname_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! BAK_Disk_A Hostname folder: $BAK_Disk_A_Hostname_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. BAK_Disk_A Hostname folder: $BAK_Disk_A_Hostname_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! BAK_Disk_A Hostname folder: $BAK_Disk_A_Hostname_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sduo mkdir -p $BAK_Disk_A_Hostname_Folder
sudo chown $USER:$USER $BAK_Disk_A_Hostname_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CHK_BAK_Disk_B_Hostname_Folder (){
echo -e "\033[32mCheck the BAK_Disk_B Hostname folder status: \033[35m($BAK_Disk_B_Hostname_Folder) \033[0m"
ls $BAK_Disk_B_Hostname_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. BAK_Disk_B Hostname folder: $BAK_Disk_B_Hostname_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[31mWarning! BAK_Disk_B Hostname folder: $BAK_Disk_B_Hostname_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. BAK_Disk_B Hostname folder: $BAK_Disk_B_Hostname_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[31mWarning! BAK_Disk_B Hostname folder: $BAK_Disk_B_Hostname_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $BAK_Disk_B_Hostname_Folder
sudo chown $USER:$USER $BAK_Disk_B_Hostname_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CHK_BAK_Disk_A_BAK_Folder (){
echo -e "\033[32mCheck the BAK_Disk_A ${BAK_Project} backup folder status: \033[35m($BAK_Disk_A_BAK_Folder) \033[0m"
ls $BAK_Disk_A_BAK_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. BAK_Disk's Backup file saving folder: $BAK_Disk_A_BAK_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no BAK_Disk's Backup file saving folder: $BAK_Disk_A_BAK_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. BAK_Disk's Backup file saving folder: $BAK_Disk_A_BAK_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! There is no BAK_Disk's Backup file saving folder: $BAK_Disk_A_BAK_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $BAK_Disk_A_BAK_Folder
sudo chown $USER:$USER $BAK_Disk_A_BAK_Folder -R
if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CHK_BAK_Disk_B_BAK_Folder (){
echo -e "\033[32mCheck the BAK_Disk_B ${BAK_Project} backup folder status: \033[35m($BAK_Disk_B_BAK_Folder) \033[0m"
ls $BAK_Disk_B_BAK_Folder > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. BAK_Disk's Backup file saving folder: $BAK_Disk_B_BAK_Folder exist, go next.\033[0m" | tee -a $LOG1
else
echo -e " >> \033[33mWarning! There is no BAK_Disk's Backup file saving folder: $BAK_Disk_B_BAK_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. BAK_Disk's Backup file saving folder: $BAK_Disk_B_BAK_Folder exist, go next.\033[0m" | tee -a $LOG1
else echo -e " >> \033[33mWarning! There is no BAK_Disk's Backup file saving folder: $BAK_Disk_B_BAK_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
sudo mkdir -p $BAK_Disk_B_BAK_Folder
sudo chown $USER:$USER $BAK_Disk_B_BAK_Folder -R

if [[ $? != 0 ]]; then
echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"
echo
exit
fi
if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m"; echo; exit; fi
fi
}

CP_TO_BAK_Disk_A (){
echo -e "\033[32mCopy the backup files to Backup_Disk_A...\033[0m"
cp $Bak_File_Name_TS $BAK_Disk_A_Bak_File_Name_TS
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. Make a copy OK - \033[35m($BAK_Disk_A_Bak_File_Name_TS) \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m($BAK_Disk_A_Bak_File_Name_TS) \033[0m" | tee -a $LOG1
echo
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Make a copy OK - \033[35m$BAK_Disk_A_Bak_File_Name_TS \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m$BAK_Disk_A_Bak_File_Name_TS \033[0m" | tee -a $LOG1; echo
echo -e " \033[35mIf you got (Permission denied) message, please perform below command and re-do again. \033[0m"
echo -e " \033[35mIt happened at fist backup, caused from created disk mount point folder ($BAK_Disk_A_Mount_Point) with sudo \033[0m"
echo -e " \033[41;37m# sudo chown $USER:$USER $BAK_Disk_A_Mount_Point \033[0m"
echo
exit
echo -e " \033[41;37m# sudo chown $USER:$USER $BAK_Disk_A_Mount_Point \033[0m"; echo; exit
fi
}

CP_TO_BAK_Disk_B (){
echo -e "\033[32mCopy the backup files to Backup_Disk_B...\033[0m"
cp $Bak_File_Name_TS $BAK_Disk_B_Bak_File_Name_TS
if [[ $? == 0 ]]; then
echo -e " >> \033[34mPass. Make a copy OK - \033[35m($BAK_Disk_B_Bak_File_Name_TS) \033[0m" | tee -a $LOG1
else
echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m($BAK_Disk_B_Bak_File_Name_TS) \033[0m" | tee -a $LOG1
echo
if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Make a copy OK - \033[35m$BAK_Disk_B_Bak_File_Name_TS \033[0m" | tee -a $LOG1
else echo -e " >> \033[41;37mFail. Make a copy failed. Exit\033[0m - \033[35m$BAK_Disk_B_Bak_File_Name_TS \033[0m" | tee -a $LOG1; echo
echo -e " \033[35mIf you got (Permission denied) message, please perform below command and re-do again. \033[0m"
echo -e " \033[35mIt happened at fist backup, caused from created disk mount point folder ($BAK_Disk_B_Mount_Point) with sudo \033[0m"
echo -e " \033[41;37m# sudo chown $USER:$USER $BAK_Disk_B_Mount_Point \033[0m"
echo
exit
echo -e " \033[41;37m# sudo chown $USER:$USER $BAK_Disk_B_Mount_Point \033[0m"; echo; exit
fi
}

echo -e "===== `date +"%Y/%m/%d %H:%M:%S"` ===== \033[45;37m$0\033[0m =====" | tee -a $LOG1
echo -e "===== \033[43;30m`date +"%Y/%m/%d %H:%M:%S"`\033[0m ===== \033[35m$0\033[0m =====" | tee -a $LOG1
CHK_PWFile
CHK_LOG_Folder
CHK_Bak_Folder
Mysql_Dump
#CHK_BAK_Disk_A
#CHK_BAK_Disk_A_Mount_Point
#CHK_BAK_Disk_A_Mount_Status
#CHK_BAK_Disk_A_Hostname_Folder
#CHK_BAK_Disk_A_BAK_Folder
#CP_TO_BAK_Disk_A
#CHK_BAK_Disk_B
#CHK_BAK_Disk_B_Mount_Point
#CHK_BAK_Disk_B_Mount_Status
#CHK_BAK_Disk_B_Hostname_Folder
#CHK_BAK_Disk_B_BAK_Folder
#CP_TO_BAK_Disk_B
CHK_BAK_Disk_A
CHK_BAK_Disk_A_Mount_Point
CHK_BAK_Disk_A_Mount_Status
CHK_BAK_Disk_A_Hostname_Folder
CHK_BAK_Disk_A_BAK_Folder
CP_TO_BAK_Disk_A
CHK_BAK_Disk_B
CHK_BAK_Disk_B_Mount_Point
CHK_BAK_Disk_B_Mount_Status
CHK_BAK_Disk_B_Hostname_Folder
CHK_BAK_Disk_B_BAK_Folder
CP_TO_BAK_Disk_B


echo
echo -e "\033[33mIf you want to check the LOG, please perform below command: "
echo -e " # cat $LOG1\033[0m"
echo
echo -e " # cat $LOG1\033[0m"; echo

+ 0
- 10
_LOG/ED8backup-Script_ED8.log Переглянути файл

@@ -1,10 +0,0 @@
===== 2019/08/11 23:49:39 ===== ./ED8backup-Script_ED8-Auto.sh =====
Start backup the Script_ED8 
Pass. Backup file saving folder: /ED/ED8/Backup_file exist, go next.
Pass. tar Script_ED8 file OK.
Pass. Make a copy file to "/ED/ED8/Backup_file". Finished!
Copy the backup files to Backup_Disk_A...
Pass. Copied to BAK_Disk_A. 
Copy the backup files to Backup_Disk_B...
Pass. Copied to BAK_Disk_B. 


+ 0
- 10
_LOG/ED8backup-Source_Files.log Переглянути файл

@@ -1,10 +0,0 @@
===== 2019/08/11 23:49:57 ===== ./ED8backup-Source_Files-Auto.sh =====
Start backup the ED8 Source_Files 
Pass. Backup file saving folder: /ED/ED8/Backup_file exist, go next.
Pass. tar Source_Files file OK.
Pass. Make a copy file to "/ED/ED8/Backup_file". Finished!
Copy the backup files to Backup_Disk_A...
Pass. Copied to BAK_Disk_A. 
Copy the backup files to Backup_Disk_B...
Pass. Copied to BAK_Disk_B. 


+ 0
- 44
_LOG/ED8backup-mysql-Auto.log Переглянути файл

@@ -1,44 +0,0 @@
===== 2019/08/11 23:49:13 ===== ./ED8backup-mysql-Auto.sh =====
>> Pass. /home/girl/PW/mysql_ED8.info exist.
>> Pass. There is a folder "/ED/ED8/Script_ED8/_LOG". 
>> Pass. Backup file saving folder: /ED/ED8/Backup_file exist, go next.
==========================================================================================
 Important! Please check below messages for making sure mysqldump be performed exactly. 
>> Pass. mysql dump w/ gzip OK. 
==========================================================================================
Starting make a copy with timastamp filename...
>> Pass. Make a copy OK - (/ED/ED8/Backup_file/backup-mysql-ED8-20190811-234913.gz) 
>> Pass. The BAK_Disk_A "/dev/sdb" be detected by lsscsi. 
>> Pass. The BAK_Disk_A mount point exist "/BAK_Disk_A"
>> Pass. The BAK_Disk_A (/dev/sdb) be mounted at "/BAK_Disk_A"
>> Pass. BAK_Disk_A Hostname folder: /BAK_Disk_A/girl-Home exist, go next.
>> Pass. BAK_Disk's Backup file saving folder: /BAK_Disk_A/girl-Home/ED8/Backup_file exist, go next.
>> Pass. Make a copy OK - (/BAK_Disk_A/girl-Home/ED8/Backup_file/backup-mysql-ED8-20190811-234913.gz) 
>> Pass. The BAK_Disk_B "/dev/sda" be detected by lsscsi. 
>> Pass. The BAK_Disk_B mount point exist "/BAK_Disk_B"
>> Pass. The BAK_Disk_B (/dev/sda) be mounted at "/BAK_Disk_B"
>> Pass. BAK_Disk_B Hostname folder: /BAK_Disk_B/girl-Home exist, go next.
>> Pass. BAK_Disk's Backup file saving folder: /BAK_Disk_B/girl-Home/ED8/Backup_file exist, go next.
>> Pass. Make a copy OK - (/BAK_Disk_B/girl-Home/ED8/Backup_file/backup-mysql-ED8-20190811-234913.gz) 
===== 2019/08/12 00:05:56 ===== ./ED8backup-mysql-Auto.sh =====
>> Pass. /home/girl/PW/mysql_ED8.info exist.
>> Pass. There is a folder "/ED/ED8/Script_ED8/_LOG". 
>> Pass. Backup file saving folder: /ED/ED8/Backup_file exist, go next.
==========================================================================================
 Important! Please check below messages for making sure mysqldump be performed exactly. 
>> Pass. mysql dump w/ gzip OK. 
==========================================================================================
Starting make a copy with timastamp filename...
>> Pass. Make a copy OK - (/ED/ED8/Backup_file/backup-mysql-ED8-20190812-000556.gz) 
>> Pass. The BAK_Disk_A "/dev/sdb" be detected by lsscsi. 
>> Pass. The BAK_Disk_A mount point exist "/BAK_Disk_A"
>> Pass. The BAK_Disk_A (/dev/sdb) be mounted at "/BAK_Disk_A"
>> Pass. BAK_Disk_A Hostname folder: /BAK_Disk_A/girl-Home exist, go next.
>> Pass. BAK_Disk's Backup file saving folder: /BAK_Disk_A/girl-Home/ED8/Backup_file exist, go next.
>> Pass. Make a copy OK - (/BAK_Disk_A/girl-Home/ED8/Backup_file/backup-mysql-ED8-20190812-000556.gz) 
>> Pass. The BAK_Disk_B "/dev/sda" be detected by lsscsi. 
>> Pass. The BAK_Disk_B mount point exist "/BAK_Disk_B"
>> Pass. The BAK_Disk_B (/dev/sda) be mounted at "/BAK_Disk_B"
>> Pass. BAK_Disk_B Hostname folder: /BAK_Disk_B/girl-Home exist, go next.
>> Pass. BAK_Disk's Backup file saving folder: /BAK_Disk_B/girl-Home/ED8/Backup_file exist, go next.
>> Pass. Make a copy OK - (/BAK_Disk_B/girl-Home/ED8/Backup_file/backup-mysql-ED8-20190812-000556.gz) 

+ 0
- 10
_LOG/ED8restore_from_local-mysql.log Переглянути файл

@@ -1,10 +0,0 @@
======= 2019/08/12 00:03:44 ==========================
2019/08/12 00:03:44 - Starting restore ED8 mysql from dumped files
1/2: The database named db_ed8_ exist, go next
2/2: Restored mysql. Finished

======= 2019/08/12 00:05:08 ==========================
2019/08/12 00:05:08 - Starting restore ED8 mysql from dumped files
1/2: The database named db_ed8_ exist, go next
2/2: Restored mysql. Finished


Завантаження…
Відмінити
Зберегти