Files
aaPanel/script/logsBackup.py
T
Jack ed55fa708d Update to 7.7.0
Since version 7.7.0, we recommend yours update python to 3.12.

[+] Using nginx technology to load static files improves access speed
[+] Refactor homepage, website, FTP, and database using vue3
[+] Table loading changed to skeleton screen
[+] Add Website statistics-v2 professional plug-in
[+] Add Home page - top 5 resource occupancy
[+] Add protection for Files management (requires Tamper-proof for Enterprise 3.7)
[+] Website, FTP, Databases page add program status
[+] Add FTP log analysis (only supports Centos)
[+] Add password-free login to phpMyAdmin
[+] Add Proxy Project in Website (Supported when web service uses Nginx)
[+] Add WP Toolkit (Pro version only)
[+] Redesigned Docker module
[+] Add WP Toolkit Protection
[+] Add WP Toolkit Backup and Restore
[+] Add WP Toolkit Migrated
[+] Add WP Toolkit Clone site (supports new domain and subdomain)
[+] Add WP Toolkit Create site from backup of other panel
[+] Add WP Toolkit support for Cron automatic backup (only save Local disk)
[+] Add WP Toolkit operation log
[+] Add Integrity check for WP Toolkit
[+] Add WP Toolkit plug-in management and themes management

[*] Optimize phpMyAdmin formula access method
[*] Optimize Home page PHP display problem
[*] Optimize jump to the login interface after the login expires
[*] Optimize automatic renewal of SSL at some times
[*] Optimize Let's Encrypt to increase application success rate

[-] Fix Logs Audit cannot be opened
[-] Fix apache URL rewrite issue
[-] Fix phpmyadmin installation problem
[-] Fix the problem that some servers cannot install software
[-] Fix upload file error
[-] Fix left menu hiding problem
[-] Fix aaPanel Mobile QR code display problem
[-] Fix problem that third-party plug-ins are not displayed in the App Store
[-] Fix issue where the menu bar is blank when opening new tabs
[-] Fixed panel not being accessible in some cases
[-] Fix the issue where Curl warning caused the inability to apply for SSL
[-] Fix Quota issues for Website, FTP, Databases
[-] Fix file interface display problem on mobile terminal
2024-07-19 11:25:10 +08:00

92 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/python
#coding: utf-8
#-----------------------------
#aaPanel
# 网站日志切割脚本
#-----------------------------
import sys
import os
import shutil
import time
import glob
os.chdir("/www/server/panel")
sys.path.append('class/')
import public
print ('==================================================================')
print( '★['+time.strftime("%Y/%m/%d %H:%M:%S")+']Cutting log')
print ('==================================================================')
print ('|--Currently retaining the latest ['+sys.argv[2]+'] copies')
logsPath = '/www/wwwlogs/'
is_nginx = False
if os.path.exists('/www/server/nginx/logs/nginx.pid'): is_nginx = True
px = '.log'
if not is_nginx: px = '-access_log'
def build_errlog(sitename):
if is_nginx:
log = sitename + '.error.log'
elif os.path.exists('/usr/local/lsws/bin/lswsctl'):
log = sitename + '-error_log'
else:
log = sitename + '_ols.error_log'
return log
def clean_backlog(logname,num):
logs=sorted(glob.glob(logname+"_*"))
count=len(logs)
num=count - num
for i in range(count):
if i>num: break;
os.remove(logs[i])
print('|---The extra log ['+logs[i]+'] has been deleted!')
def split_logs(oldFileName,num,site_name):
global logsPath
errlog_name = build_errlog(site_name)
old_errlog = logsPath + errlog_name
if not os.path.exists(oldFileName):
print('|---'+oldFileName+'file does not exist!')
return
clean_backlog(oldFileName,num)
clean_backlog(old_errlog,num)
newFileName=oldFileName+'_'+time.strftime("%Y-%m-%d_%H%M%S")+'.log'
shutil.move(oldFileName,newFileName)
new_errlog = build_errlog(site_name)+'_'+time.strftime("%Y-%m-%d_%H%M%S")+'.log'
shutil.move(old_errlog, newFileName)
if not os.path.exists('/www/server/panel/data/log_not_gzip.pl'):
os.system("gzip %s" % newFileName)
os.system("gzip %s" % new_errlog)
print('|---The log has been cut to:' + newFileName + '.gz')
else:
print('|---The log has been cut to:'+newFileName+'.log')
def split_all(save):
sites = public.M('sites').field('name').select()
for site in sites:
oldFileName = logsPath + site['name'] + px
split_logs(oldFileName,save,site['name'])
if __name__ == '__main__':
num = int(sys.argv[2])
if sys.argv[1].find('ALL') == 0:
split_all(num)
else:
siteName = sys.argv[1]
if siteName[-4:] == '.log':
siteName = siteName[:-4]
elif siteName[-11:] == '-access_log':
siteName = siteName.replace("-access_log",'')
else:
siteName = siteName.replace("_ols.access_log", '')
oldFileName = logsPath+sys.argv[1]
split_logs(oldFileName,num,siteName)
if is_nginx:
os.system("kill -USR1 `cat /www/server/nginx/logs/nginx.pid`")
elif os.path.exists('/usr/local/lsws/bin/lswsctl'):
os.system('/usr/local/lsws/bin/lswsctl restart')
else:
os.system('/etc/init.d/httpd reload')