How to Bulk Delete Deleted Documents

Hi,

How to Bulk Delete the Deleted Documents instead of one by one?

Any button and server script?

Hi @Nitin_Chintamani,

If the user has system manager rights then will do it.

Thank You!

1 Like

Thank you for your reply but if I have more than 60K entries, its a very time consuming task and it also consumes my daily time limit on Frappe Cloud.

In the file
/home/<erpnextUSER>/frappe-bench/apps/frappe/frappe/desk/doctype/bulk_update/bulk_update.py you could temporarily change the limit of 500 to get a longer list but even if you DO know what you’re doing, it would be very dangerous.

Thanks, but deleting one by one is still a big task. There should be something like Delete All in Error Log

If you want to clear things in the error log, you can try this…
mysql -uroot -p -A; #the -A speeds up opening the relevant DB

and then run the delete command something like below (tuned to your requirements[method like ‘%send_mail%’;] and with YOUR DBname[_fhjaeouy1oweyut9c4]. You can look in the table for a specific entry that you want to delete to figure out what the query should contain

use _fhjaeouy1oweyut9c4;
delete from `tabError Log` where method like '%send_mail%';
commit;
/q

@NCP
How safe is it to delete Deleted Documents ?

What about other tables? How safe is it to clear older records from some table like [version-12],

tabVersion
tabComment
tabRoute History
tabAccess Log
tabData Import 
tabData Import Legacy
tabFile
tabActivity Log
tabEmail Queue Recipient
tabEmail Queue
tabOAuth Bearer Token

Also, there’s thousands of Data Import Legacy records, with files; as they are successful, if we delete them, shall there be any issue?

and, what’s __global_search this has millions+ records?

First, sorry to reopen this thread after a year, but I find it important to give a proper solution here, this thread being the top Google search result when looking for “Frappe bulk delete”.

@Nitin_Chintamani
I propose to simply use Log Settings.
It allows to choose an expiration duration for most of the logs, including Email Queue, Deleted Documents, etc…
For deleting the documents, just choose 1 day duration for the related doctype and wait a bit.

Any document older than the chosen duration will be automatically deleted in a clean way. In frappe version 15 more doctypes are available in log settings, but beware if you are using a site migrated from version 14 to version 15, you first need to delete the “Error Snapshot” row, it causes an issue as this doctype doesn’t exist in version 15 anymore.

Btw if you want to delete any other doctype, using the system console if server scripts are enabled or the server console directly, this kind of script would do the trick without any broken link risks:

documents=frappe.get_list("YourDoctype",filters={"Your filters"}
for document in documents:
	frappe.delete_doc(("YourDoctype",document.name)

Don’t forget to check commit before executing if you use the system console or it won’t commit.

@fnrfarid
To answer your question, deleting deleted documents directly through SQL should not have any nefarious effect as logs documents are supposed to not be the target of any link, but any custom app,doctype or field could still target them.