[Dovecot] Resync quota to mysql script
I changed some quota options in my dovecot config (eg. excluded folders) but afaik this only affects new mail and there is no magic command to recalculate the quota (or is there?). So I wrote this little python script to do this, maybe someone finds it useful.
It can output the sql statements (dovecot 1.0/1.1 and 1.2 format) or just print out quota usage to console.
Download at : http://wgwh.ch/dovecot/quotasync.py , run-at-own-risk and do-whith-the-code-what-you-want applies.
# cd /path/to/a/Maildir # quotasync.py INBOX : 21 messages 516739 bytes .postfix : 982 messages 7572888 bytes .bn_archiv : 77 messages 2092454 bytes .python : 2748 messages 19877135 bytes .testfolder.subfolder1.subsubfolder1 : 2 messages 19443 bytes .testfolder.subfolder2 : 1 messages 9044 bytes .testfolder : 0 messages 0 bytes .Trash : 146 messages 1702297 bytes .Drafts : 0 messages 0 bytes .Sent : 0 messages 0 bytes .Spam : 2459 messages 16152165 bytes .testfolder.subfolder1 : 4 messages 13359 bytes
TOTAL: 6440 messages 47955524 bytes
Example mysql output,dovecot 1.2 format: # quotasync.py -o mysql -a user@domain.com INSERT INTO quota (username,bytes,messages) VALUES ('user@domain.com',47963905,6441) ON DUPLICATE KEY UPDATE bytes=47963905,messages=6441;
Example mysql output, dovecot 1.1 format, Spam folder excluded # quotasync.py -o mysql -a user@domain.com -d 1.1 -e .Spam INSERT INTO quota (username,path,current) VALUES ('user@domain.com','quota/messages',3982) ON DUPLICATE KEY UPDATE current=3982; INSERT INTO quota (username,path,current) VALUES ('user@domain.com','quota/storage',31811740) ON DUPLICATE KEY UPDATE current=31811740;
You can pipe this output directly to mysql. eg.: quotasync.py -a user@domain.com -o mysql | mysql yourdatabase
run quotasync.py --help to see all options
On Jun 9, 2009, at 6:27 AM, Oli Schacher wrote:
I changed some quota options in my dovecot config (eg. excluded
folders) but afaik this only affects new mail and there is no magic command to recalculate the quota (or is there?).
Well, you can delete the user's quota row from SQL and it will get
recalculated later. And if you want to force the recalculation
immediately, you can log in as the user and issue GETQUOTAROOT INBOX
command.
participants (2)
-
Oli Schacher
-
Timo Sirainen