netbox-attachments
netbox-attachments copied to clipboard
Deleting attachments
Idea - https://github.com/netbox-community/netbox/discussions/11336
https://pypi.org/project/django-unused-media/
Solution:
- Install django-unused-media in requirements
- Create a script to
manage.py
to call the method for deleting files - example of creating own manage.py method
- https://github.com/amyasnikov/validity/pull/45/files
I've just installed the plugin today and I'm learning how it works. Maybe it would be useful to have a config option to delete files automatically? This is also relevant when updating an attachment with a new filename, the old one is retained.
Garbage collection of completely orphaned files would be very nice but should be also somehow limited. Unless unlinked from an object and confirmed as obsoleted intentionally the attachments should not be garbage collected. Also when overwritten then the original version should be kept in history unless completely unlinked from an object and claimed as unneeded somehow explicitely. ... Just consider some users overwritting important attachments by mistake etc. which is a scenario one would generally like to recover from.
Therefor I see an attachment as something that could have unique identity and only it's content and metadata could change through it's lifetime (e.g., hand crafted network schema for the customer etc.)
Hello,
can anybody test the version 5.1.4-b1 ?
It adds command remove_orphaned_netbox_attachments
to manage.py
It should scan the netbox_attachmments
folder and delete all files which are not assigned to any object.
There is also an --dry-run
option to just run the command without deleting the objects.
Also use the -v2
option to print out the file names which will be deleted.
Any other options you can find by python /opt/netbox/netbox/manage.py remove_orphaned_netbox_attachments --help
I've tested it against my netbox-docker installation and it seems that it works correctly.