MySQL Automatic backup under CentOS

Source: Internet
Author: User
Tags mysql automatic backup mysql backup

#!/bin/Bashdb_user="Root"db_passwd="123456"db_name="test_db"#进入备份目录将之前的移动到old目录cd/mnt/backup/BakmysqlEcho "Bakmysql Directory now"MVtest_db*/mnt/backup/BakmysqloldEcho "Old databases is moved to Bakmysqlold folder"#备份目录backup_dir="/mnt/backup/bakmysql"#时间格式 Time=$(Date+"%y-%m-%d"#mysql Backup commands, note that there are spaces and no spaces mysqldump-U$DB_USER-P$DB_PASSWD $db _name >"$backup _dir/$db _name"-"$time. SQL"Echo "your database backup successfully completed"#这里将7天之前的备份文件删掉SevenDays=$(Date-d-7day +"%y-%m-%d")if[-f/mnt/backup/bakmysqlold/pashanhu-$SevenDays. sql] ThenRM-rf/mnt/backup/bakmysqlold/pashanhu-$SevenDays. SQLEcho "You have delete 7days ago Bak sql file"ElseEcho "7days ago Bak sql file not exist"Echo "Bash complete"fi

Then use the following command to step into the system's scheduled tasks

Crontab-e00 * * *./usr/sbin/bakmysql. SH

Save after you exit.

may need to restart crontab enable command:/sbin/service crond restart

MySQL Automatic backup under CentOS

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.