MySQL regularly backs up the database shell

Source: Internet
Author: User
Tags vars

One, prepare the shell script.

View copy print?
  1. vi/home/zhangy/database_bak.sh
  2. #!/bin/sh
  3. # File:/home/zhangy/database_bak.sh
  4. # Database Info bakupmysql TANK 2009/11/04
  5. db_user="root" #用户名
  6. db_pass="********" # password
  7. Db_name="MyBlog" # The data name to be backed up
  8. <span id=more-161></span># Others VARs
  9. Date= ' Date+%y_%m_%d ' # dates to be backed up
  10. Yesterday= 'date-d yesterday +%y_%m_%d ' # Delete yesterday's backup
  11. bin_dir="/usr/local/mysql/bin"
  12. bck_dir="/home/zhangy/database_bak" # Backup path
  13. CD $BCK _dir
  14. # Delete Previous backup of this database, because my Linux also has 2G hard disk space, depressed.
  15. If [ -F $YESTERDAY$DB _name". sql"]
  16. Then
  17. Rm-f $YESTERDAY$DB _name". sql"
  18. Fi
  19. # Backup
  20. ${bin_dir}/mysqldump--opt-u${db_user}-p${db_pass} ${db_name} > ${bck_dir}/${date}${db_name}.sql
vi/home/zhangy/database_bak.sh #!/bin/sh # File:/home/zhangy/database_bak.sh # Database Info bakupmysql  TANK 2009 /11/04 db_user= "root"   #用户名 db_pass= "********"   &NB Sp                          ,         &NB Sp                 # password Db_name= "MyBlog"             &NB Sp                          ,         &NB Sp

    # The data name to be backed up# Others VARs date= ' date +%y_%m_%d ' # to back up the date yesterday= ' date-d yesterday +     

%y_%m_%d ' # Delete yesterday's backup bin_dir= "/usr/local/mysql/bin" bck_dir= "/home/zhangy/database_bak" # Backup path
CD $BCK _dir # Delete Previous backup of this database, because my Linux also has 2G hard disk space, depressed. If [-F $YESTERDAY $db_name ". sql"] then rm-f $YESTERDAY $db_name ". sql" FI # backup ${bin_dir}/mysqldump--opt-u${db_user}- P${db_pass} ${db_name} > ${bck_dir}/${date}${db_name}.sql

Second, regular implementation
Put the shell inside the crontab.

# See if Crond is started
[Email protected] cron]# Ps-e|grep Crond
21519? 00:00:00 Crond

# Open Crontab
[Email protected] cron]# CRONTAB-E
# Add a line inside
* * * * */home/zhangy/database_bak.sh

# Check to see if you've added
[Email protected] cron]# crontab-l
#
# do not EDIT this FILE manually!! Use Crontab-e INSTEAD.
#

# <minute>

* * * * * */usr/sbin/run-cron/etc/cron.hourly
* * * * */usr/sbin/run-cron/etc/cron.daily
* * 0/usr/sbin/run-cron/etc/cron.weekly
1 * */usr/sbin/run-cron/etc/cron.monthly
* * * */home/zhangy/www/bb.php
* * * * */sbin/shutdown-h now
* * * * */home/zhangy/database_bak.sh

And then quit.

MySQL regularly backs up the database shell

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.