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