BASH SCRIPT AND CRON FOR mysqldump PROCESS(LINUX):

This script will help to take mysql dump particularly when you want to exclude few db in server.


* kindly update the required database list on the file: db.list

With password:

#!/bin/bash
#script will use for when you take db backup for selective range of db's
for i in `cat db.list`
do mysqldump --user="username" --password="password" $i > $i.sql
if [ $? -ne 0 ]
then
echo $i Failed >> db_filed.txt
else
echo $i Success >> db_success.txt
fi
done


Without password:

#!/bin/bash
#script will use for when you take db backup for selective range of db's
for i in `cat db.list`
do mysqldump $i > $i.sql
if [ $? -ne 0 ]
then
echo $i Failed >> db_filed.txt
else
echo $i Success >> db_success.txt
fi
done


Add to cron:

# vi mysql_dump_cron.sh
#!/bin/bash
#script will use for when you take db backup for selective range of db's
BACKUP=DB_BACKUP_`date +%Y-%m-%d-%H:%M`
mkdir -p /path/to/BACKUP
for i in `cat /path/to/db.list`
do mysqldump $i > /path/to/BACKUP/$i.sql
if [ $? -ne 0 ]
then
echo $i Failed >> /path/to/BACKUP/db_filed.txt
else
echo $i Success >> /path/to/BACKUP/db_success.txt
fi
done


Daily cron:

0 0 * * * /path/to/the/script/mysql_dump_cron.sh > /dev/null 2>&1

Comments

Popular posts from this blog

Resolved: DOCKER: Error response from daemon: Could not attach to network / rpc error: code = 7 desc = network not manually attachable.

yum failed 6 times. Cannot continue!

unexpectedly shrunk window (repaired) in dmesg log - TCP Peer