Mysql automatic backup script _ MySQL

Source: Internet
Author: User
Tags mysql automatic backup
#! Binbash # autobackupmysqlshell # bycsy2015-11-11 # automatic database backup and add Task Scheduler script # define variable BAK_CMDusrbinmysqldumpBAK_HOSTlocalhostBAK_DBcsyBAK_USERrootBAK_PASS12
#! /Bin/bash # auto backup mysql shell # by csy 2015-11-11 # automatically back up the database and add the task plan script # define the variable ============== = BAK_CMD =/usr/bin/mysqldumpBAK_HOST = localhostBAK_DB = csyBAK_USER = rootBAK_PASS = "123456" BAK_DIR =/tmp/mysqlbackup/BAK_DATE = 'date + % f' # Environment Test... ....... if [$ UID-ne 0]; then echo-e "\ 033 [32 m must use the ROOT user to execute this script. \ 033 [0 m "exitfiif [! -D $ BAK_DIR]; then mkdir-p $ BAK_DIR echo-e "\ 033 [35 m $ BAK_DIR this directory is created successfully !!! \ 033 [1 m "else echo-e" \ 033 [35 m $ BAK_DIR this directory already exists... \ 033 [0 m "fi # Official backup ..... $ BAK_CMD-h $ BAK_HOST-u $ BAK_USER-p $ BAK_PASS-d $ BAK_DB> $ BAK_DIR/csy _ $ BAK_DATE.sqlif [$? -Eq 0]; thenecho-e "\ 033 [34m database backup has been completed .... \ 033 [1 m "echo" backup directory: $ BAK_DIR "elseecho-e" \ 033 [34m data backup error, please check .... \ 033 [0 m "fi # Automatically delete backup data 30 days ago find $ BAK_DIR/-mtime + 30 | xargs rm-rf {}\; if [$? -Eq 0]; thenecho-e "\ 033 [37 M deleted the backup data 30 days ago... \ 033 [1 m "elseecho-e" \ 033 [37 m command execution error or directory not found, check \ 033 [0 m "fi # create an automatic backup schedule task grep" back_mysql "/var/spool/cron/root>/dev/nullif [$? -Ne 0]; thenecho "30 20 ** 5/root/shell/back_mysql>/tmp/mysql. log 2> & 1">/var/spool/cron/rootfi

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.