If you planning to back u your IMAP mail server it could be best to use a professional software such as Shoviv IMAP Email backup and restore tool. This tool not only backup your IMAP Emails but also allow to restore them back to your IMAP server.
Gmail Backup tool
This post is about how you can back up your Gmail emails on a computer or hard drive in PST, EML, MBOX and MSG file formats.