Deletes orphaned files in Mattermost Community/Team Edition. Safe, doesn't require Enterprise.
1.4K
Safely deletes orphaned files in Mattermost Community/Team Edition. No Enterprise. No nonsense.
/mattermost/data).Free your storage without paying for βretentionβ features.
The project is built on a modern technology stack:
Sources/
βββ Program.cs # Application entry point
βββ Controllers/
β βββ JobController.cs # REST API endpoints
βββ Services/
β βββ ReportService.cs # Retention reports management
βββ Models/
β βββ RetentionReport.cs # Report data model
β βββ RetentionReportFileInfo.cs # File processing details
βββ Database/
β βββ AppDbContext.cs # Entity Framework context
β βββ Models/
β βββ MattermostPost.cs # Mattermost posts model
β βββ MattermostFileInfo.cs # File information model
βββ Jobs/
βββ RetentionJob.cs # Main file cleanup job
Please note: The
DryRunmode is enabled by default, meaning that files will not be deleted but only logged. Change this setting tofalsein production after testing. Author is not responsible for data loss. If you have any errors or questions, please open an issue.
docker-compose.yml file:services:
mattermost-real-retention:
image: bvdcode/mattermost-real-retention:latest
restart: always
# Optional: Expose API endpoints for manual control and monitoring
# Comment out the ports section if you don't need external API access
ports:
- "8080:8080" # API endpoints (optional)
environment:
- PostgresHost=postgres
- PostgresPort=5432
- PostgresUser=mattermost
- PostgresPassword=changeme
- PostgresDatabase=mattermost
- DryRun=true # Set to false for actual deletion
- DelayBetweenFilesInMs=0 # Optional: delay between file processing
volumes:
- /path/to/mattermost/data:/mattermost/data:rw
docker-compose up -d
docker run -d \
--name mattermost-retention \
--restart always \
-p 8080:8080 \ # Optional: Only if you need API access
-e PostgresHost=your_postgres_host \
-e PostgresPort=5432 \
-e PostgresUser=mattermost \
-e PostgresPassword=your_password \
-e PostgresDatabase=mattermost \
-e DryRun=true \
-v /path/to/mattermost/data:/mattermost/data:rw \
bvdcode/mattermost-real-retention:latest
Note: Remove the
-p 8080:8080line if you don't need external access to the API endpoints. The service will work perfectly for automatic cleanup without exposing any ports.
| Variable | Description | Default | Required |
|---|---|---|---|
PostgresHost | PostgreSQL server host | postgres-server | β |
PostgresPort | PostgreSQL port | 5432 | β |
PostgresUser | PostgreSQL username | mattermost_server | β |
PostgresPassword | PostgreSQL password | - | β |
PostgresDatabase | Database name | mattermost | β |
DryRun | Test mode (doesn't delete files) | true | β |
DelayBetweenFilesInMs | Delay between file processing (ms) | 0 | β |
The service uses the same PostgreSQL connection settings as your Mattermost server. Ensure that:
posts and fileinfo tablesfileinfo table records (only when DryRun=false)The service provides REST API endpoints for monitoring and manual control. Note: API access is optional - the service works automatically without exposing any ports.
Returns detailed reports of all retention job executions.
Response:
[
{
"dryRun": true,
"createdAt": "2025-01-15T10:30:00Z",
"directory": "/mattermost/data/",
"totalFilesCount": 1523,
"foldersCount": 45,
"processedFiles": [
{
"relativePath": "20241201/abc123/image.jpg",
"length": 245760,
"deleted": true,
"result": "File not found in database - deleted from filesystem"
}
]
}
]
Usage:
# Only works if ports are exposed
curl http://localhost:8080/status
Manually triggers the retention cleanup job.
Response:
"Job 'RetentionJob' has been triggered successfully."
Usage:
# Only works if ports are exposed
curl -X POST http://localhost:8080/trigger
Note: The trigger endpoint is useful for testing and manual cleanup runs. The job will still respect the
DryRunsetting.
/mattermost/data/ directoryYYYYMMDD formatfileinfo table/mattermost/data/)fileinfo table in the databaseThe service deletes files in the following cases:
fileinfo tableposts.deleteat > 0)fileinfo.deleteat > 0)Use the /status endpoint to programmatically monitor retention job executions:
DryRun=false[Information] Starting retention job with delay 0 ms and dry run mode True.
[Information] Found 1523 files in 45 date directories in /mattermost/data/.
[Information] Preloading database posts for performance optimization...
[Information] Preloaded 987543 active posts from the database.
[Information] Preloading database files for performance optimization...
[Warning] File 20241201/abc...123/image.jpg not found in the database - deleting from filesystem.
[Warning] File 20241201/def...456/document.pdf is marked deleted - deleting file and database record.
[Information] Dry run enabled, skipping actual deletion.
[Information] Retention job completed. 42 files deleted, 1523 files total.
cd Sources
dotnet restore
dotnet build
cd Sources
dotnet run
docker build -t mattermost-retention ./Sources
The project uses GitHub Actions for automatic building and publishing of Docker images:
bvdcode/mattermost-real-retentionghcr.io/bvdcode/mattermost-real-retentionImages are built automatically on every push to the main branch.
Tested on production scale:
DryRun=true to assess cleanup volumeDryRun=true - files are not deleted, only loggedContributions to the project are welcome:
This project is distributed under the MIT License. See the LICENSEβ file for details.
If you have questions or issues:
Content type
Image
Digest
sha256:377ba3de3β¦
Size
92.5 MB
Last updated
about 1 year ago
docker pull bvdcode/mattermost-real-retention