Prune Orphaned Uploads
Over time your installation may accumulate orphaned files. These are files which remain in the
storage/app/ directory but have no matching upload record in the database, for example
attachments belonging to tickets which have since been deleted. Orphaned files consume disk space
without serving any purpose.
The uploads:prune-orphans command finds these files and deletes them. It checks the following directories:
email_logexportspublicselfservicetickets
A file is considered orphaned when there is no upload record in the database with a matching folder and hash (the filename is the upload hash). As a safeguard, files modified within the last 24 hours are never deleted, so uploads still in progress aren't affected.
The command operates on the storage driver configured by FILESYSTEM_DISK. If you've moved your
files to an S3 compatible service, as described in Cloud Storage,
it prunes the bucket rather than the local storage/app/ directory. Note that on S3 compatible
services a directory containing no files is reported as missing and skipped, which is expected and can be
ignored.
Usage
We strongly recommend running the command with the --dry-run option the first time. This lists
the files which would be removed without deleting anything, so you can review them before proceeding.
Usage on Docker
docker exec -u supportpal supportpal php artisan uploads:prune-orphans --dry-run
Usage on Linux
php artisan uploads:prune-orphans --dry-run
Example Output
Dry-run mode — no files will be deleted.
Orphan: tickets/3bb30c24bfe8db80f5e6aeb814f3dbf2c8ebd7db
Orphan: tickets/6ded3dee83dea6c89e28c6f56dfebbd72407b458
Orphan: tickets/f534bbca61e06961815729907733c3c61ba88380
Found 3 orphaned file(s).
Once you're happy with the list of files reported, run the command again without the --dry-run
option to permanently delete them:
php artisan uploads:prune-orphans
Orphan: tickets/3bb30c24bfe8db80f5e6aeb814f3dbf2c8ebd7db
Orphan: tickets/6ded3dee83dea6c89e28c6f56dfebbd72407b458
Orphan: tickets/f534bbca61e06961815729907733c3c61ba88380
Deleted 3 orphaned file(s).
--dry-run.
Usage Options
| Option | Description |
|---|---|
--dry-run |
List orphaned files without deleting them. |
--force |
Force the operation to run when in production. |
Running in Production
When the help desk is running in the production environment, the command displays the following warning and asks you to confirm before deleting anything:
THIS COMMAND WILL PERMANENTLY DELETE FILES IN THE STORAGE/APP/ DIRECTORY THAT HAVE NO MATCHING UPLOAD DATABASE RECORD. MAKE SURE YOU HAVE A BACKUP BEFORE PROCEEDING!
Are you sure you want to run this command? (yes/no) [no]
Pass the --force option to skip this prompt. This is required when the command is run without an
interactive terminal, such as from a script or scheduled task, otherwise it's cancelled without deleting
anything. The prompt isn't shown when using --dry-run, as no files are deleted.
php artisan uploads:prune-orphans --force