Linux_centos_ setting up MySQL scheduled backups

Source: Internet
Author: User

First, see if the necessary components are installed

[Email protected]/]# Rpm-qa | grep croncronie-1.4.11-14.el7_2.1.x86_64cronie-anacron-1.4.11-14.el7_2.1.x86_ 64crontabs-1.11-6.20121102git.el7.noarch

If not, perform

[[email protected] system]# yum install vixie-cron[[email protected] system]# Yum install Crontabs

II. basic Commands

[[email protected]/]#/sbin/service crond start|stop|restart|reload# View status [[email protected]/]# service Crond status

Iii. Creating a timed task

[[email protected]/]# vi/usr/sbin/bakmysql...# mysql user name db_user= "root" # mysql password db_passwd= "root" # database name to back up Db_name= " BACKDB "# Backup location backup_dir="/home/back/mysql_back "# file name set to TIME format Time=" $ (date + "%y%m%d%h%m%s") "/usr/local/mysql/bin/ MYSQLDUMP-U$DB_USER-P$DB_PASSWD $db _name > "$backup _dir/$db _name" _ "$time. sql" ...
Note: There is no space between-P and $db _passwd, otherwise $db_passwd will be treated as parameter [database name] To resolve note:/usr/local/mysql/bin/is the MySQL installation directory, it must be so used otherwise it is possible to back up as empty

Iv. Modify the File Bakmysql property to make it executable

[Email protected]/]#  chmod +x/usr/sbin/bakmysql

V. Create a timed task using crontab

[Email protected]/]#  crontab-e
* * * */usr/sbin/bakmysql #是每天23:00 execution

Vi. start crontab and add it to boot

[Email protected]/]#/sbin/service crond start[[email protected]/]# chkconfig--level + crond on

Vii. View crontab Service status

[[email protected]/]#  service Crond Status

PS: Check if the crontab service is set to boot

[Email protected]/]#  ntsysv #如果没安装可以用yum安装一下

Linux_centos_ setting up MySQL scheduled backups

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.