Offlineimap is a tool to backup or sync IMAP accounts. Backing up an IMAP account to a local folder is easy.
Create a file `.offlineimaprc` in your home directory like described here: http://www.offlineimap.org/doc/quick_start.html.
Now you can run `offlineimap` from your command line. Type in your password and the download will start.