[Dovecot] Resync quota to mysql script

Oli Schacher dovecot at lists.wgwh.ch
Tue Jun 9 16:27:42 EEST 2009


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 at domain.com
INSERT INTO quota (username,bytes,messages) VALUES
('user at 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 at domain.com -d 1.1 -e .Spam
INSERT INTO quota (username,path,current) VALUES
('user at domain.com','quota/messages',3982) ON DUPLICATE KEY UPDATE
current=3982;
INSERT INTO quota (username,path,current) VALUES
('user at domain.com','quota/storage',31811740) ON DUPLICATE KEY UPDATE
current=31811740;


You can pipe this output directly to mysql.
eg.:
quotasync.py -a user at domain.com -o mysql | mysql yourdatabase

run quotasync.py --help to see all options




More information about the dovecot mailing list