MySQL database automatic backup script sharing

Source: Internet
Author: User

The first few blogs have been published in succession to all technical details of the turntable network, as follows:

Baidu Network Disk Crawler

Chinese Word segmentation algorithm

Invite friends to register

JS Pagination Part Code

This blog I will continue to expose the code of automatic database backup. So to speak, no database, everything is an egg, no database backup, everything is an egg, you can imagine how important database backup. Not Linux, will not write the shell friend trouble first to fill. But you said I am a bull, do not fill also can understand, that no problem, haha, nonsense don't say. The usual, on the code:

#!/bin/bashtime=$ (date + "%d-%m-%y") pre=/home/ubuntu  #想放到那里麻烦自己配置下哈if  [ ! -d  "$ pre/data_backup/$time " ]then  mkdir -p  $pre/data_backup/$time   echo " create  $pre/data_backup/$time "else  echo " exist  $pre/data_backup/$time "fiif [  -d  "$pre/data_backup/$time"  ]then mysqldump -h10.66.102.75 -uroot -p123456  --opt winrun user >  $pre/data_backup/$time/user.sql mysqldump - h10.66.102.75 -uroot -p123456--opt winrun categoryinfo  >  $pre/data_ backup/$time/categoryinfo.sql mysqldump -h10.66.102.75 -uroot -p123456 --opt  winrun admin_info >  $pre/data_backup/$time/admin_info.sql mysqldump -h10.66.102.75  -uroot -p123456 --opt winrun admin_loginfo >  $pre/data_backup/$time/ Admin_loginfo.sql mysqldump&nBsp;-h10.66.102.75 -uroot -p123456 --opt winrun admin_notice_info  >   $pre/data_backup/$time/admin_notice_info.sql mysqldump -h10.66.102.75 -uroot - p123456--opt winrun advertising_info  >  $pre/data_backup/$time/advertising_ Info.sql mysqldump -h10.66.102.75 -uroot -p123456--opt winrun ajax_request_info   >  $pre/data_backup/$time/ajax_request_info.sql mysqldump -h10.66.102.75 - uroot -p123456 --opt winrun bt_file_info  >  $pre/data_backup/$time/bt_ file_info.sql echo  "backup finished"  cd  $pre/data_backup  #enter  dir  zip -r  $time .zip  $time/ rm -fr  $time   #delete  cd - echo  "Zip backup database finished" else echo  "Can not find backup file "Fi

Note that my password I have changed, this can not tell you, so like copy of the child trouble himself the password. Below I teach you to play the next Crotab, the code is as follows:

# edit this file to introduce tasks to be run by cron.# # each task to run has to be defined through a single  line# indicating with different fields when the task will  be run# and what command to run for the task## to  define the time you can provide concrete values for# minute  (m), hour  (h), day of month  (DOM), month  (Mon), # and day  of week  (DOW)  or use  ' * '  in these fields  (for  ' any '). # # notice that tasks will be started based on the cron ' s  system# daemon ' s notion of time and timezones.## output of  the crontab jobs  (including errors)  is sent through# email to the user the  crontab file belongs to  (unless redirected). ## for example, you  can run a backup of all your user accounts# at 5  a.m every week with:# 0 5 * * 1 tar -zcf /var/backups/ Home.tgz /home/## for more information see the manual pages of  crontab (5)  and cron (8) ## m h  dom mon dow    Command10 1 * * 1,3,5  /home/backup.sh >> /home/backup.log

Useful is the bottom of this sentence, see No, backup has to have a log, or who knows what the backup to look like, do not understand crontab trouble himself under Baidu, I also temporarily to you do not understand.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/80/6A/wKiom1dAfLaR-38zAAAWLq160FQ714.png "title=" Database backup Result "alt=" Wkiom1daflar-38zaaawlq160fq714.png "/>

The above is the result of the backup, note that after the backup is the form of compressed package, so please install the compression tool, Apt-get installed XXXX will not be the trouble Baidu, really simple into a dog.

Technology is to share, open source, go to the turntable is not stingy with any technology, welcome attention to Weibo or, at any time to communicate.

MySQL database automatic backup script sharing

Related Article

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.