#!/usr/bin/env python3 """Inspect seaweed bucket prefixes + try vacuum reclaim.""" from __future__ import annotations import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) cmd = r""" set -e while IFS= read -r line; do case "$line" in DY_S3_*=*) export "$line" ;; esac; done < <(grep -E '^Environment=DY_S3_' /etc/systemd/system/douyinweb-api.service | sed 's/^Environment=//' | tr ' ' '\n' | grep DY_S3_) # also from show eval $(systemctl show douyinweb-api -p Environment --value | tr ' ' '\n' | grep '^DY_S3_' | sed 's/^/export /') cd /opt/douyinWEB/backend ./.venv/bin/python - <<'PY' from collections import defaultdict from app import s3_storage from app.config import settings client=s3_storage._client() # list ALL keys by prefix top-level sizes=defaultdict(lambda:[0,0]) # count, bytes token=None total=0 oldest=None newest=None while True: kw={'Bucket':settings.s3_bucket,'MaxKeys':1000} if token: kw['ContinuationToken']=token r=client.list_objects_v2(**kw) for o in r.get('Contents') or []: k=o['Key']; total+=1 top=k.split('/',1)[0] if '/' in k else k if k.startswith('covers/avatars/'): top='covers/avatars' elif k.startswith('covers/'): top='covers/session' sizes[top][0]+=1; sizes[top][1]+=int(o.get('Size') or 0) lm=o.get('LastModified') if lm: ts=lm.timestamp() oldest=ts if oldest is None or tsnewest else newest if not r.get('IsTruncated'): break token=r.get('NextContinuationToken') print('total_objects', total) import time print('oldest_age_days', None if oldest is None else round((time.time()-oldest)/86400,2)) print('newest_age_days', None if newest is None else round((time.time()-newest)/86400,2)) for k,v in sorted(sizes.items(), key=lambda x:-x[1][1]): print(f'{k}: n={v[0]} bytes={v[1]} ({v[1]/1e6:.1f}MB)') PY echo '---volume files---' ls -lhS /data/seaweed/volume | head -30 du -sh /data/seaweed/volume /data/seaweed/filer /data/seaweed/master echo '---weed ports---' ss -lntp | grep -E 'weed|8333|9333|18888|19333|28080' || true echo '---vacuum via weed shell if any---' # master port from systemd systemctl cat douyinweb-sw-master douyinweb-sw-volume douyinweb-s3 2>/dev/null | head -80 """ _i, o, e = c.exec_command(cmd, timeout=120, get_pty=True) chan = o.channel start = time.time() while True: if chan.recv_ready(): sys.stdout.write(chan.recv(8192).decode("utf-8", "replace")) sys.stdout.flush() if chan.exit_status_ready(): while chan.recv_ready(): sys.stdout.write(chan.recv(8192).decode("utf-8", "replace")) sys.stdout.flush() break if time.time() - start > 110: print("TIMEOUT") break time.sleep(0.1) print("\n[exit", chan.recv_exit_status(), "]") c.close()