Gmail Backup is a freeware that allows you to backup and restore your Gmail email account. It backups all the emails in your account along with the attachments and also preserves the labels.
Download the application and install it, you just need to enter your gmail username and password for it to recover all the emails. You need to enable IMAP access in your gmail account to backup emails using Gmail Backup. To do so, go to settings > Forwarding and POP/IMAP and enable IMAP access. After entering the username and password specify the directory to store the backed up emails. Then click backup.
Optionally one can use date range for taking backup. It stores all the emails in .eml files, so you can access these emails using other programs like MS Outlook Express and Mozilla Thunderbird. You can also restore the gmail emails to another account or the same account using the recover function of gmail backup. This works with Google Apps domains also, so if you want to migrate all your regular gmail account to Google Apps domain this is a good tool to do that.
This is a useful tool to backup Gmail regularly to avoid any unexpected surprises. Gmail backup is a freeware for Windows, Linux. Windows version has a GUI but Linux (also works with Mac) version is command-line only.