Cleaning up files in Server

Hello.

One of our servers is runing out of space and before investing in an upgrade, I am trying to clean it up and avoid that upgrade as much as I can becouse it might be costly for our organization.

The main usage of our system is based on a tracker program that has images atached to the events of the TEIs. Those images are uploaded by an android app instaled in a Tablet.

One of the tasks I have been doing to free disk space is the deletion of files no longer conected with any TEI. I managed to delete the files older than the first event of the first enrollment in the server.

But I am wondering if there is a way I can know wich files are no longer connected with TEIS (caused by the deletion of TEIS, for example or caused by bad communication between the Tablet and the server).

I have been searching and there is no way I can connect the name of the file shown in the event in DHIS2 with the name of the file in the file system. I understand this is for security reasosn. Is there a way DHIS2 can clean up files no longer connected? Is there any tool I can use to delete those files and free disk space?

Thank you very much in advance.,

1 Like

Hi @JaimeLopez

You can run a query to list all the file resources currently referenced (the fileresource table)

SELECT * FROM fileresource;

The storagekey is usually the name or identifier used to store the file in file system.

using a WHERE event.uid NOT IN query that can be applied to either Enrollment or events

NOTE: Please ensure you double-check the results of your query before performing any delete operations

Hello RC

Thanks for your answer.
My DHIS server is in version 2.37.
How can I execute that query? Do I need to get into command line for the server and use psql? Or there is another way within DHIS2? I am familiar with sql and DHIS2, but not with postgres/DHIS 2 sql queries or sql views.

I am trying to use api call from postman and the response for https://https://<>/api/fileresource is “The origin server did not find a current representation for the target resource or is not willing to disclose that one exists”

Hello again RC.

I magnaged to execute query in Maintenance app.

Thanks a lot.

2 Likes