MySQL Automatic backup script

Source: Internet
Author: User
Tags mysql automatic backup

Mysqldump () {echo  "start   $mysql _dbname1  $mysql _dbname2  backup ..." if [ -d  "${backdir" }/${date} " ];thenecho " Mysql database dir already exists. " exit 1elsemkdir -p ${backdir}/${date}echo  "Start Backup  ${mysql_dbname1}  ..."/usr/bin/ mysqldump -u  $mysql _user -p$mysql_passwd  $mysql _dbname1 > ${backdir}/${date}/ ${mysql_dbname1}.sqlsleep 1if [ $? -eq 0 ];thenecho  "${mysql_dbname1}  backup successful! " elseecho  "${mysql_dbname1} backup failed!" exit 1fiecho  "Start Backup  ${mysql_dbname2}  ..."/usr/bin/mysqldump -u  $mysql _user -p$ mysql_passwd  $mysql _dbname2 > ${backdir}/${date}/${mysql_dbname2}.sqlsleep 1if [  $? -eq 0 ];thenecho  "${mysql_dbname2} backup successful!" elseecho  "${mysql_dbname2} backup failed!" exit 1fifireturn $?} Backup () {mysqldumpif [ $? -eq 0 ];thenecho  "${mysql_dbname1} and ${ mysql_dbname2}  Backup succeeded! "Fi}backuppython# writes to Crontab, which is automatically backed up 00:01 daily. [[Email protected] ~]# cat /etc/crtoncat: /etc/crton: no such file  or directory[[email protected] ~]# cat /etc/crontab shell=/bin/bashpath=/ sbin:/bin:/usr/sbin:/usr/binmailto=roothome=/# for details see man 4 crontabs#  EXAMPLE OF JOB DEFINITION:#&NBSP:---------------- minute  (0 - 59) #  |  .------------- hour  (0 - 23) # |  |  .--------- - day of month  (1 - 31) # |  |  |  .-------  month  (1 - 12)  or jan,feb,mar,apr ...# |  |  |   | &NBSP---- day of week  (0 - 6)   (sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat# |  |   |  |  |# *  *  *  *  * user-name  command to be executed00 01 * * * * root /bin/bash  /backup/backup.sh


This article is from the "less stubborn" blog, please be sure to keep this source http://xushaojie.blog.51cto.com/6205370/1783609

MySQL Automatic backup script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.