Don't use IMAP for backups, use POP3 instead. If your e-mails are deleted in the cloud, your local IMAP e-mails will disappear as well.
Also, POP3 is not folder-aware. You can only access your inbox over POP3. If you want to backup anything (e.g. drafts, sent mail, etc), then you need more than POP3.
Vice-versa too. I learnt this the hard way :(