A maintenance script finds an old directory with a familiar data structure. It might be a live archive, or it might be the recovery copy you will need after a bad update.
Scope cleanup explicitly
Give the process a defined working root and a clear set of recognized generated files. Exclude backup locations and recovery artifacts by design. Do not recursively delete every matching extension across the project.
Resolve paths before acting and reject unexpected links or locations. A relative path that worked in a command-line test can point somewhere else when a web request starts it.
Test the exclusion
Create a fictional backup tree beside the test data and confirm that maintenance leaves it untouched. Include similarly named directories, nested folders and unknown files. Verify the final report against the actual filesystem changes.
A backup also needs its own deliberate retention and restore policy, but that is a separate operation with different evidence and authority. Do not let routine cache cleanup make that decision accidentally.
A safe maintenance routine knows what it owns. Everything outside that scope should remain untouched unless a separate, justified operation says otherwise.