A poor man's data rentention policy tool for dendrite home servers
408
A data retention policy tool for Dendrite servers.
The original author of this script is Sebastian Spaeth (sspaeth). All props to him!
Cleanmedia helps manage media storage on Dendrite servers by implementing configurable retention policies for both remote and local media files. It can remove old media files based on age while preserving essential content like user avatars.
The easiest way to run Cleanmedia is using Docker. You can either use it as a standalone container or integrate it with your docker-compose.yml:
services:
cleanmedia:
hostname: cleanmedia
image: rogsme/cleanmedia
volumes:
- /your/dendrite/config/location:/etc/dendrite
- /your/dendrite/media/location:/var/dendrite/media
environment:
- CRON=0 0 * * * # Run daily at midnight
- CLEANMEDIA_OPTS=-c /etc/dendrite/dendrite.yaml -t 30 -l # 30 day retention, include local files
depends_on:
- monolith
⚠ MAKE SURE YOUR MOUNTPOINTS CORRESPOND TO THE MOUNTPOINTS OF YOUR DENDRITE DOCKER INSTALLATION!
CRON: Cron schedule expression (default: 0 0 * * * - daily at midnight)CLEANMEDIA_OPTS: Command line options for cleanmedia (default: -c /etc/dendrite/dendrite.yaml -t 30 -n -l)/etc/dendrite: Dendrite configuration directory/var/dendrite/media: Dendrite media storage directoryCleanmedia uses Poetry for dependency management. To install:
# Install Poetry if you haven't already
pip install poetry
# Install dependencies
poetry install
-c, --config: Path to dendrite.yaml config file (default: config.yaml)-m, --mxid: Delete a specific media ID-u, --userid: Delete all media from a local user ('@user:domain.com')-t, --days: Keep remote media for specified number of days (default: 30)-l, --local: Include local user media in cleanup-n, --dryrun: Simulate cleanup without modifying files-q, --quiet: Reduce output verbosity-d, --debug: Increase output verbositydocker compose up -d cleanmedia
environment:
- CRON=0 */6 * * * # Run every 6 hours
- CLEANMEDIA_OPTS=-c /etc/dendrite/dendrite.yaml -t 14 -l -d # 14 day retention with debug logging
docker compose run --rm cleanmedia python cleanmedia.py -c /etc/dendrite/dendrite.yaml -t 1 -l -d -n
poetry run python cleanmedia.py --help
-l flagThe tool performs consistency checks and warns about:
The project includes a comprehensive test suite using pytest:
# Run tests
poetry run pytest
# Run tests with coverage report
poetry run pytest --cov=. --cov-report=xml
# Run specific test file
poetry run pytest tests/test_cleanmedia.py
Multiple tools ensure code quality:
# Run linting
poetry run ruff check
# Run formatting check
poetry run ruff format --check
# Run type checking
poetry run mypy .
The project uses pre-commit hooks for consistent code quality. Install them with:
poetry run pre-commit install
This code is released under the GNU GPL v3 or any later version.
Warning: There is no warranty for correctness or data that might be accidentally deleted. Use with caution and always test with --dryrun first!
Contributions are welcome! Please ensure you:
Content type
Image
Digest
sha256:93f0694b4…
Size
26.9 MB
Last updated
over 1 year ago
docker pull rogsme/cleanmedia