Skip to content

Clean up old debug files

POST
/api/system/debug/cleanup

Clean up old debug files older than specified retention period.

Performs intelligent age-based cleanup of debug files with configurable retention policy. Safely deletes files older than the specified number of days while preserving recent files for troubleshooting.

Query Parameters:

  • keep_days: Number of days to retain files (default: 7, minimum: 0)

Returns:

  • status: Operation status (“success” or “error”)
  • message: Human-readable operation summary
  • files_deleted: Count of files successfully deleted
  • space_freed_mb: Total disk space freed in megabytes
  • files_kept: Count of recent files preserved
  • details: List of deleted filenames with sizes (first 10)

Cleanup Process:

  • Parses timestamps from filenames for accurate age determination
  • Falls back to file modification time if timestamp parsing fails
  • Calculates cutoff date based on keep_days parameter
  • Safely deletes files older than cutoff with error handling
  • Tracks freed disk space for reporting
  • Logs all deletion operations for audit trail

Safety Features:

  • Only deletes recognized debug file types
  • Validates keep_days parameter (must be non-negative)
  • Continues cleanup even if individual file deletions fail
  • Provides detailed reporting of kept vs deleted files
  • Never deletes files from other directories

Validation:

  • HTTPException (400): If keep_days is negative

Example Usage:

  • POST /debug/cleanup?keep_days=7 - Keep last 7 days
  • POST /debug/cleanup?keep_days=30 - Keep last 30 days
  • POST /debug/cleanup?keep_days=0 - Delete all debug files

Example Response:

{
    "status": "success",
    "message": "Cleanup complete. Deleted 15 files older than 7 days. Kept 8 recent files.",
    "files_deleted": 15,
    "space_freed_mb": 42.35,
    "files_kept": 8,
    "details": [
        "crashdata-2024-12-01T10-30-00-000Z.json (2.5 MB)",
        "dumplog-2024-12-02T14-20-00-000Z.txt (1.8 MB)"
    ]
}
keep_days
Keep Days
integer
default: 7

Successful Response

DebugCleanupResponse

Response model for debug cleanup operations.

Provides comprehensive cleanup results including deletion counts, disk space freed, retention counts, and detailed file listings. Used by debug cleanup endpoints to report cleanup operation results with full transparency.

Fields: status: Operation status (“success”, “error”, “partial”) message: Human-readable operation summary files_deleted: Count of files successfully deleted space_freed_mb: Total disk space freed in megabytes files_kept: Count of files preserved based on retention policy details: List of deleted filenames with sizes (limited to first 10)

Example: json { "status": "success", "message": "Cleanup complete. Deleted 15 files older than 7 days. Kept 8 recent files.", "filesDeleted": 15, "spaceFreedMb": 42.35, "filesKept": 8, "details": [ "crashdata-2024-12-01T10-30-00-000Z.json (2.5 MB)", "dumplog-2024-12-02T14-20-00-000Z.txt (1.8 MB)" ] }

object
status
required
Status
string
message
required
Message
string
filesDeleted
Filesdeleted
integer
0
spaceFreedMb
Spacefreedmb
number
0
filesKept
Fileskept
integer
0
details
Details
Array<string>

Validation Error

HTTPValidationError
object
detail
Detail
Array<object>
ValidationError
object
loc
required
Location
Array
msg
required
Message
string
type
required
Error Type
string
input
Input
ctx
Context
object