King0770-Notes-Nuking everything in a folder: Difference between revisions
No edit summary |
No edit summary |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
=King Notes nuking everything in a folder= | |||
This comes up once in a while in support; someone has thousands or millions of items in a folder, and they need to nuke the folder now.<br> | This comes up once in a while in support; someone has thousands or millions of items in a folder, and they need to nuke the folder now.<br> | ||
Line 18: | Line 19: | ||
zmmailbox -z -m user01@domain.com dm $msg | zmmailbox -z -m user01@domain.com dm $msg | ||
done | done | ||
</pre></code> | |||
You can also query against mysql in a for-loop, to remove 1000 messages at a time. | |||
<code><pre> | |||
e.g. | |||
for i in `mysql mboxgroup71 -NBe "select id from mail_item where mailbox_id='3871' AND folder_id='2' LIMIT 1000;"`; do zmmailbox -z -m user@example.com deleteMessage $i; done | |||
</pre></code> | </pre></code> | ||
You will need to know how the zimbra account is structured, see https://wiki.zimbra.com/wiki/Account_mailbox_database_structure | |||
Notable bugs:<br> | Notable bugs:<br> | ||
http://bugzilla.zimbra.com/show_bug.cgi?id=38473 | http://bugzilla.zimbra.com/show_bug.cgi?id=38473 | ||
[[Category:Command Line Interface]] | |||
[[Category:mysql]] | |||
[[Category:King0770-Notes]] |
Latest revision as of 19:41, 7 December 2018
King Notes nuking everything in a folder
This comes up once in a while in support; someone has thousands or millions of items in a folder, and they need to nuke the folder now.
Usually, the command to nuke everything in a folder is:
zmmailbox -z -m user01@domain.com ef /MyStuff
However, if the folder actually has "millions" of items in it, you may be inclined to remove 100 items at a time, and let the script run until all the items are removed.
Example:
#!/bin/bash
for msg in `zmmailbox -z -m user01@domain.com search -l 100 "in:MyStuff" | grep conv | awk '{ print $2 }' | sed -e 's/^-//'`
do
echo "Removing "$msg""
zmmailbox -z -m user01@domain.com dm $msg
done
You can also query against mysql in a for-loop, to remove 1000 messages at a time.
e.g.
for i in `mysql mboxgroup71 -NBe "select id from mail_item where mailbox_id='3871' AND folder_id='2' LIMIT 1000;"`; do zmmailbox -z -m user@example.com deleteMessage $i; done
You will need to know how the zimbra account is structured, see https://wiki.zimbra.com/wiki/Account_mailbox_database_structure
Notable bugs:
http://bugzilla.zimbra.com/show_bug.cgi?id=38473