只保留最近 MAX_BACKUPS 个备份
()
| 24 | |
| 25 | |
| 26 | def cleanup_backups(): |
| 27 | """只保留最近 MAX_BACKUPS 个备份""" |
| 28 | pattern = str(OPENCLAW_CFG.parent / 'openclaw.json.bak.model-*') |
| 29 | baks = sorted(glob.glob(pattern)) |
| 30 | for old in baks[:-MAX_BACKUPS]: |
| 31 | try: |
| 32 | pathlib.Path(old).unlink() |
| 33 | except OSError: |
| 34 | pass |
| 35 | |
| 36 | |
| 37 | def main(): |