How to auto backup a Gmail account to a QNAP NAS

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
[/share/Gmail-Backup] # mkdir

That’s about it. Try a test run using this command line: backup /share/Gmail-Backup/ 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] # -h


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!

15 replies on “How to auto backup a Gmail account to a QNAP NAS”

  1. Guys, that may take some time. But if you urgently need a Gmail backup solution you could have a look a this thread:

    This is the post I used as a starter for my current Getmail based backup job which has been running perfectly for almost a year now. In order to use IMAP instead of POP3 I had to patch Getmail so it won’t reset the read marks on my emails.


  2. I followed the tutorial but I am experiencing the same problem described by Josh! :-(
    Looking forward for an upated version.

  3. Hi, Woudl also love to know best current method to automatically backup my gmail accounts to my NAS.

    Appreciate any advice anyone here may have.

    Thanks for this great article.

  4. Hi!

    Happy New Year!…

    I’m also eager to read this new post about Getmail!

    Thank you for sharing!

  5. Josh, I should have written an updated version of this post using open source software (Getmail) ages ago. It’s on my TODO list for over a year now…


  6. Hi mate,

    Great article!

    I’m seeing some errors when running “ipkg install /share/Gmail-Backup/py25-gmail-backup_1.07-1…”

    See below :

    Clearing state_want and state_flag for pkg=py25-gmail-backup (arch_priority=0 flag=16 want=2)
    Nothing to be done
    An error ocurred, return value: 4.
    Collected errors:
    Cannot find package py25-gmail-backup.
    Check the spelling or perhaps run ‘ipkg update’
    [/share/Gmail-Backup] #

    I ran ipkg update as recommended in the error but receive the following error:

    [/share/Gmail-Backup] # ipkg update
    Updated list of available packages in /opt/lib/ipkg/lists/cs08q1armel
    An error ocurred, return value: 1.
    Collected errors:
    ipkg_download: ERROR: Command failed with return value 1: `wget –passive-ftp -q -P /opt/ipkg-OpZAuJ
    [/share/Gmail-Backup] #

    Any ideas?

    Cheers Josh

  7. Well, in that case I look forward to your Getmail howto. ;) Thanks again for your efforts, much appreciated!

  8. The problem with Gmail-Backup is that it’s closed software, the Python source code isn’t available. So technically I’m not allowed to provide an .ipk package. I found out about this when I tried to fix a problem regarding read marks. The way Gmail-Backup accesses the email also removes the unread mark from every unread mail. Unfortunately, the creators seem to have pretty much abandoned the project. So, I had a closer look at Getmail which is open source software. I will have to write another how-to for Getmail and how to fix Getmail so it won’t reset the unread marks just like Gmail-Backup does.


  9. Wow, awesome! Came looking for this exact functionality after recent reports that some gmailboxes are emptied after an error.
    Thanks a lot for the article, looking forward to part three!

Comments are closed.