It’s pretty straightforward to (incrementally) backup all emails in a Gmail account to a QNAP NAS. There’s a QNAP NAS solution using Getmail but it comes with some limitations. I prefer to use Gmail-Backup. It doesn’t need any configuration files and it doesn’t have a 100 messages per session limit. It stores all mails in the .eml format, which not only works on Windows PCs but is compatible with Apple Mail as well. You can even restore deleted emails using Gmail-Backup from the NAS back to a Gmail account.
Here’s how I installed Gmail-Backup on my QNAP TS-439 PRO II+. This tutorial should work with all Intel-based QNAP TS-* models but obviously I only have the 439 to test with. I’m looking forward for your feedback if it works on your QNAP NAS model as well. Please make sure you enabled IMAP in your Gmail account settings. Gmail-Backup works for “Gmail for your domain” (it’s part of “Google Apps” now) accounts as well.
The tutorial is divided into three parts. The first part shows how to install the Optware QPKG on the NAS. This package installer is needed in order to (easily) install Python on the NAS. The 2nd part deals with the installation of Gmail-Backup and the third shows how to automate the backup using cron. It probably is helpful to have some command line skills.
Part I: Installing the Optware QPKG on the NAS
Log in to your QNAP NAS admin user interface and go to -> Application Servers -> QPKG Plugins, hit the GET QPKG button on the upper right side. Download Optware IPKG (Itsy Package Management System) for your QNAP NAS model, unzip it and upload the .qpkg file in the tab called “Installation”. Once it is installed, make sure it’s enabled too.
Part II: Installing Gmail-Backup
Go to -> Access Right Management -> Share Folders and create a new shared folder named “Gmail-Backup”. I’d set group permissions to the admin group (r/w) for that new share. This is the place where all downloaded emails will go to.
Download the Gmail-Backup IPKG installation package from this site’s download area, unzip it and copy the .ipk file to the new Gmail-Backup share using a file transfer method of your choice. This is necessary because Gmail-Backup isn’t part of the Optware IPKG online repository.
Open a console, log on to the QNAP NAS using ssh and install Python 2.5 using IPKG:
[~] # ipkg install python25
If the Optware QPKG has been installed properly, it will now try to download and install Python. Once Python is installed, install Gmail-Backup:
[~] # ipkg install /share/Gmail-Backup/py25-gmail-backup_1.07-1_i686.ipk
Now let’s create subdirectories for every Gmail account in the Gmail-Backup share (this is just a sample, these are obviously fake addresses):
[~] # cd /share/Gmail-Backup [/share/Gmail-Backup] # mkdir email@example.com [/share/Gmail-Backup] # mkdir firstname.lastname@example.org
That’s about it. Try a test run using this command line:
gmail-backup.sh backup /share/Gmail-Backupemail@example.com firstname.lastname@example.org mypassword --stamp
The –stamp parameter is somewhat important. If you don’t use it, Gmail-Backup has to dig through all emails to see which ones haven’t been backed up yet. Using the stamp parameter will make incremental backups super fast.
Use the -h parameter to get more information about Gmail-Backup:
[/share/Gmail-Backup] # gmail-backup.sh -h Description =========== Program for backup and restore of your GMail mailbox. You will need to activate the IMAP access to your mailbox, to do so, please open your GMail settings and under POP/IMAP tab activate this option. The messages are stored in the local directory in files which names follow the format YYYYMMDD-hhmmss-nn.eml where YYYY is the year, MM the month number, DD is the day number, hh are hours, mm are minutes and ss are seconds when the e-mail was SENT. For the case there is more emails with the same timestamp there is the number nn which starts with value 1. Label assignment is stored in the file labels.txt which is the plain text file and it pairs the emails stored in the file described above with the assigned labels.
I didn’t have time to finish the third part of the tutorial which will show how to create a cron job to automate the incremental Gmail backup every night. I will publish it in a separate post in the next few days, so stay tuned!