The Linux scheduled task system backs up data at 00:00 every day. Log storage directory: optwwwlogsnginx file storage directory: optwwwlogsall Log File Format: yyyy-mm-dd.tar.bz2 #! Binbash # poweredbywww.baidu.org.tw # author: kethinc # useage: crontab-e #00 *** shoptww
The Linux scheduled task system backs up data at 00:00 every day.
Log storage directory:/opt/www/logs/nginx
Record Filing storage directory:/opt/www/logs/all
Log File Format: yyyy-mm-Dd.Tar.bz2
#! /Bin/bash
# PowerEdBy www. baIdU.org.tw
# Author: kethiNc
# Useage:Crontab-E
#0 0 *** sh/opt/www/logs/logstore. sh>/dev/null 2> & 1
# The Nginx logs bak
Work_path = "/opt/www/logs"
Logs_path =$ {work_path} "/nginx"
Store_path =$ {work_path} "/all/" $ (Date-D "yesterday" + "% Y ")
Yesterday_logs_path = $ (date-d "yesterday" + "% Y-% m-% d ")
Yesterday_logs _FileZookeeper yesterday_logs_path).tar.bz2
Cd$ Work_path
Mv$ {Logs_path }$ {yesterday_logs_path}
Mkdir-P $ {logs_path}
/Etc/init. d/nginx reload # reload nginx because all the original log files have been moved and the file needs to be generated again to avoid some errors (I think there may be no tests)
Tar-jcvf $ {yesterday_logs_file} $ {yesterday_logs_path}
Mkdir-p $ {store_path}
Mv $ {yesterday_logs_file }$ {store_path}
Rm-Rf $ {yesterday_logs_path}
Usage:
Save the script file/opt/www/logs/logstore. sh
Edit the scheduled task configuration file: crontab-e
Enter 0 0 **** sh/opt/www/logs/logstore. sh>/dev/null 2> & 1 in the last line