technical skills grow

Responsive Ads Here

Thursday, December 24, 2020

Shell script for take daily backup in linux

I want to take database backup daily so i will write shell script for take daily backup of database 

 user="******"
pwd="****"

[ -d /home/backup_mysql ] || mkdir -p /home/backup_mysql
backup_path="/home/backup_mysql"
date=$(date +"%d-%b-%Y:%H:%M:%S")
file_name="/home/backup_mysql/syncing_log_$date.txt"
#host_name="192.168.103.54"


##############Backup##Database##########################
for db_name in $(mysql   -u $user  -p$pwd  -e  'SHOW DATABASES;' |grep -v -E '^Database$|information_schema|mysql|performance_schema|db_config|sys|innodb|tmp|test')
do
mysqldump  --single-transaction --max-allowed-packet=1G --routines  -u $user -p$pwd  $db_name  | gzip -c  > $backup_path/$db_name-$date.sql.gz

if [ "$?" -eq 0 ]
then
        echo -e  "mysqldump of $db_name is successfully done" >> $file_name
else
         echo -e "mysqldump failed" >> $file_name
         exit 1
fi

done
find /home/backup_mysql -mtime +5 -delete


No comments:

Post a Comment

Powered by Blogger.

Labels

Contact Form

Name

Email *

Message *

Search This Blog

Blog Archive

Ad Code

Responsive Advertisement

Recent Posts