0% found this document useful (0 votes)
26 views

Alleditor

Uploaded by

Admin Manager
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Alleditor

Uploaded by

Admin Manager
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#!

/bin/bash

# MySQL database connection parameters


MYSQL_USER="root"
MYSQL_PASSWORD="MySQL#2023"
MYSQL_HOST="localhost"
MYSQL_PORT="3306"
read -p "Nitin sir approval received? (yes/no) " yn
if [ $yn = "yes" ]; then
read -p "Backup request e-mail approval received? (yes/no) " bryn
if [ $bryn = "yes" ]; then
cat /op1.txt
read -p "Please enter server ID for backup : " source_server_id
read -p "Please enter source database name for backup : " source_db
read -p "Please enter target server ID for backup : " target_server_id
read -p "Please enter target database name for backup : " target_db
read -p "Please enter employee id : " emp_id
char="_"
ssh_port=' '
underscore_count=$(awk -F ${char} '{print NF-1}' <<< "${target_db}")
IFS='_' read -r -a array <<< "$target_db"
array_length=${#array[*]}
p=$(($array_length - 1))
echo arrayp::${array[$p]}
if [ $array_length -gt 1 ]; then
if [[ "${array[$p]}" =~ ^[0-9]+$ ]]; then
if [ $emp_id -eq ${array[$p]} ]; then
echo "Target database name has employee id suffix"
else
echo "Target database name does not have employee id suffix"
fi
else
echo "Target database employee prefix missing"
fi
else
echo "Target database employee prefix missing"

exit 1
fi
op=$(mysql --login-path=admin_server -e "select ip as
ip_addr,mysql_password,ssh_port from admin.database_list_master where
id="$source_server_id)
pass=$(echo ${op} | cut -d ' ' -f5)
ip_addr=$(echo ${op} | cut -d ' ' -f4)
ssh_port=$(echo ${op} | cut -d ' ' -f6)
disk_space_flag='true'
df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $6 " " $4 }' | while read
-r output;
do
partition=$(echo "$output" | awk '{ print $1}')
usage=$(echo "$output" | awk '{ print $2 }' )
n_free="${usage%?}"
p_usage=${usage: -1}
if [ "$p_usage" = "G" ] && [ "$partition" = "/" ]; then
if [ "$n_free" -lt 5 ]; then
disk_space_flag='false'
fi
fi
if [ "$p_usage" = "G" ] && [ "$partition" = "/var" ]; then
if [ "$n_free" -lt 10 ]; then
disk_space_flag='false'
fi
fi
done
if [ $disk_space_flag='true' ]; then
if [ -d /var/lib/mysql/$target_db ] ; then
count=$(find /var/lib/mysql/$target_db -maxdepth 1 -type f|wc -l)
if [ "$count" -eq 1 ]; then

echo "Sufficient disk space available."


echo "Database already created."
echo "Backup can be done."
ssh -p ${ssh_port} root@${ip_addr} /backup/b.sh $source_db
scp root@${ip_addr}:/backup/$source_db.sql.gz /backup
else
echo "Database already exists. Drop and create empty database"
fi
else
echo "Database does not exist. Please create empty database"
fi
else
echo disk space not sufficient $partition $usage $n_free $p_usage
fi
fi
fi

You might also like