Kani999 / netbox-attachments

Plugin to manage attachments for any model
Apache License 2.0
55 stars 4 forks source link

Deleting attachments #22

Open Kani999 opened 1 year ago

Kani999 commented 1 year ago

Idea - https://github.com/netbox-community/netbox/discussions/11336

Kani999 commented 1 year ago

https://pypi.org/project/django-unused-media/

Kani999 commented 1 year ago

Solution:

llamafilm commented 2 months ago

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.

mjf commented 2 weeks ago

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.)

Kani999 commented 2 weeks ago

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

Kani999 commented 2 weeks ago

I've tested it against my netbox-docker installation and it seems that it works correctly.