Topic:
Backup Log
Xiaoming is a server administrator who needs to back up the forum data every day (here we replace with the log), back up the day's logs and delete the previous logs. and 年-月-日
the format of the file name after the backup. Alternatives.log is below/var/log/.
Goal
- To add a scheduled task to a Shiyanlou user
- Regular backup of Alternatives.log to/home/shiyanlou/tmp/directory at 3 o'clock in the morning every day
- The naming format is
年-月-日
, for example, today is April 1, 2017, then the file name is2017-04-01
Tips
- Date
- Crontab
- CP (Backup)
- Write it in crontab with a command, without writing a script.
Note: If fail does not have any prompt information, please refresh the page. Note Crontab's program users
crontab -e 表示为当前用户添加计划任务sudo crontab -e 表示为root用户添加计划任务
Answer:
1. Start the log server
sudo service rsyslog start
2. Start the crontab service
sudo cron-f &
3. Enter the crontab file
crontab-e
4. Edit Auto-start content
0 3 * * * cp/var/log/alternatives.log/home/shiyanlou/tmp/' date+%y-%m-%d '
If cron-f & startup failure occurs
Rm-rf/var/run/crond.pid
Restart Service Rsyslog Start
Linux system backup logs