20 Jun
shell script to create Mysql database backup
On linux machine to create daily backup of selected database we can write a simple script and can add this script in daily cron.
3. Mysql backup or For DB backup #!/bin/sh #---------------------------------------------------- # Purpose = a simple mysql database backup script. # Created on 18-06-2015 # version 1.0. # Author = Rajeev Achra #---------------------------------------------------- # 1. set up all the mysqldump variables according to mysql user FILE=minime.sql.`date +"%Y%m%d"` DBSERVER=127.0.0.1 DATABASE=XXX USER=XXX PASS=XXX DESDIR=/dest_path/ # 2. in case you run this more than once a day, remove the previous version of the file unalias rm 2> /dev/null rm ${FILE} 2> /dev/null rm ${FILE}.gz 2> /dev/null # 3. do the mysql database backup (dump) # use this command for a database server on a separate host: #mysqldump --opt --protocol=TCP --user=${USER} --password=${PASS} --host=${DBSERVER} ${DATABASE} > ${FILE} # use this command for a database server on localhost. add other options if need be. mysqldump --opt --user=${USER} --password=${PASS} ${DATABASE} > ${DESDIR}${FILE} # 4. gzip the mysql database dump file gzip $DESDIR$FILE # 5. uncomment below if want to show the result #echo " ${DESDIR}${FILE}.gz was created:" #ls -l ${DESDIR}${FILE}.gz
I am a software engineer who specializes in Internet applications. I have worked with a wide variety of technologies and programming languages to open source LAMP environments. I have more than 6 years of object-oriented programming experience and am highly proficient in ActionScript, PHP, MYSQL, JavaScript, Jquery and a multitude of other technologies used in modern web applications.
Follow me
Latest posts by Rajeev Achra (see all)
- Jquery webcam plugin - June 19, 2016
- How To Add and Delete Users on a CentOSServer - June 5, 2016
- How To Set Up vsftpd on CentOS 6 - June 5, 2016