Since nobody mentioned it, imapsync[1] is a gorgeous command line utility that does one thing and does it well: copy an IMAP account from server A to server B, by sync only, so you can stop / disconnect at any time and continue where the copy left.
We use it to transfer around email hosting, but it's also suitable for backups due its sync only mechanism.