LINUX under the use of Crontab scheduled backup log __linux

Source: Internet
Author: User

Refer to two better documents.

Http://nic.qhu.edu.cn/data/2005/0907/article_41.htm

Http://lostinmymind.blogchina.com/2239184.html

There are probably two kinds of crontab, one is to modify the global configuration file/etc/crontab, the other is to run the command crontab-e directly.

Global configuration does not have detailed test, it seems to run directly crontab-e convenient.

1. Execute command crontab-e, at this time the system will open a VI editor.

2. Input

* * */home/bakuplog.sh

Indicates that the script bakuplog.sh is run 23:59 every day. The previous time format is "M H d d cmd". Of which, M stands for minutes (0~59), H stands for hours (0~23), D stands for days (1~31), M for month (1~12), D for days of the week (0~6,0 for Sunday). * represents any. For example 01 * * * * indicates 01 minutes per hour.

3. Edit vi/home/bakuplog.sh, Enter script

#!/bin/sh
mv/var/log/pix.log/var/log/back/
#移动日志
Service Syslog Restart
#重启服务
Gzip-9/var/log/back/pix.log
#压缩
Mv/var/log/back/pix.log.gz/var/log/back/log ' Date +$ (date|cut-c 25-28)%m%d '. gz
#更名
# ' Date +$ (date|cut-c 25-28)%m%d ' indicates the system date, month and year. Note that the symbol ' is not a single quote, which is the key below ESC.

OK, the test succeeded under CentOS 3.4. The result is log20051111.gz.

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.