CentOS crontab Timer Execute script auto back up file sync data

Source: Internet
Author: User

This article explains the timing plan from the installation to an automatic duty example
Install Crontab:
[Root@centos ~]# Yum Install Vixie-cron
[Root@centos ~]# Yum Install Crontabs

Description
Vixie-cron packages are Cron's main programs;
The Crontabs package is a program used to install, uninstall, or enumerate the tables used to drive the cron daemon.
//+++++++++++++++++++++++++++++++++++
Cron is a built-in service for Linux, but it does not automatically get up, you can start and close the service in the following ways:
/sbin/service crond Start//boot service
/sbin/service Crond Stop//Off service
/sbin/service crond Restart//Restart service
/sbin/service Crond Reload//Reload Configuration

See Crontab Service Status: Service Crond status
Manually start the Crontab service: Service Crond start
To see if the Crontab service is set to boot, execute command: NTSYSV
Join the boot auto start:
Chkconfig–level Crond on

1,crontab command
Feature Description: Set timer.
Syntax: crontab [-u < user name >][configuration file] or crontab [-u < user name >][-ELR]
Supplemental Note: Cron is a resident service that provides the function of timers to allow users to execute preset instructions or programs at a specific time. The timer function can be used as long as the user edits the timer's configuration file. The configuration file format is as follows:
Minute Hour Day Month DayOfWeek Command

Parameters
-e Edit the user's timer settings.
-l lists the user's timer settings.
-R Deletes the user's timer settings.
-u< User name > Specifies the name of the user to set the timer.

2,crontab format
Basic format:
* * * * command
Time-sharing and Lunar Week command

The 1th column represents minutes 1~59 per minute or/1
The 2nd column represents the hour 1~23 (0 for 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
The 5th list of the week 0~6 (0 for Sunday)
6th column the command to run
Some examples of crontab files:
* * * * * * * */USR/LOCAL/ETC/RC.D/LIGHTTPD Restart the above example shows 21:30 restart Apache per night.

4 1,10,22 * * */USR/LOCAL/ETC/RC.D/LIGHTTPD Restart the above example shows 1, 10, 22nd 4:45 restart Apache.

1 * * * 6,0/USR/LOCAL/ETC/RC.D/LIGHTTPD Restart the above example shows that every Saturday, Sunday 1:10 restart Apache.

0,30 18-23 * * * * */USR/LOCAL/ETC/RC.D/LIGHTTPD Restart the above example indicates that Apache is restarted every 30 minutes between 18:00 and 23:00 every day.

0 * * * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD Restart the above example indicates that the 11:00 PM restarts Apache every Saturday.

/1 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart restart Apache every hour

23-7/1 * * * * * * */usr/local/etc/rc.d/lighttpd restart 11 o'clock to the morning 7, restart Apache every hour.

0 4 * mon-wed/usr/local/etc/rc.d/lighttpd Restart monthly 4th and restart Apache every Monday to Wednesday 11.

0 4 1/USR/LOCAL/ETC/RC.D/LIGHTTPD * Restart January 1 restart Apache at 4 points

/30 * * */usr/sbin/ntpdate 210.72.145.44 sync time every half hour

The CRONTAB command has 3 main parameters:
-E: Edit the user's crontab.
-L: Lists the contents of the user's crontab.
-r: Deletes the user's crontab content.

Execute CRONTAB-E, will automatically open the editor, you can edit your own crontab file, syntax and/etc/crontab file, the difference is just, do not have to point out the execution of the user, edited after save. Crontab-l used to view the internal energy of their crontab files, crontab-r delete their cron

Well-known data is very important
Write a simple MySQL data file backup

VI write a file with the end of. Sh
Within the same

#!/bin/bash
# #wholly backup
tar-czpf/var/database/mysql/db_ ' Date +%y%m%d '. Tar.gz/var/lib/mysql

command
crontab-e 

new Open VI content for
2 * * * root/usr/loal/script/backup  Script path
save exit

service Crond  Status See if it is running state  

to complete a simple backup script here  
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.