30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import os, shutil, glob
|
|
from datetime import datetime
|
|
|
|
ARCHIVE = '/home/hmo/MoFin/archive/old-files-20260720'
|
|
os.makedirs(ARCHIVE, exist_ok=True)
|
|
|
|
# 1. /home/hmo 根目录旧日志(>10天)
|
|
count = 0
|
|
for f in glob.glob('/home/hmo/*.log'):
|
|
age_d = (datetime.now().timestamp() - os.path.getmtime(f)) / 86400
|
|
if age_d > 10:
|
|
shutil.move(f, os.path.join(ARCHIVE, os.path.basename(f)))
|
|
count += 1
|
|
print(f' log: {os.path.basename(f)} ({age_d:.0f}d)')
|
|
print(f'logs archived: {count}')
|
|
|
|
# 2. 旧 bot 文件
|
|
for f in ['/home/hmo/xmpp_zhiwei_bot.py.bak', '/home/hmo/run_zhiwei_bot.py', '/home/hmo/xmpp_bot_rest.py']:
|
|
if os.path.exists(f):
|
|
shutil.move(f, os.path.join(ARCHIVE, os.path.basename(f)))
|
|
print(f' bot: {os.path.basename(f)}')
|
|
|
|
# 3. 数据目录 bak 文件
|
|
for f in ['/home/hmo/web-dashboard/data/watchlist.json.bak2',
|
|
'/home/hmo/.hermes/profiles/position-analyst/data/mofin.db.bak']:
|
|
if os.path.exists(f):
|
|
shutil.move(f, os.path.join(ARCHIVE, os.path.basename(f)))
|
|
print(f' bak: {os.path.basename(f)}')
|
|
|
|
print('DONE ->', ARCHIVE) |