Recently, I had a bit of a data loss scare where I couldn’t access my Google Account for a few hours. In the end it turned out to be a well-meaning Google protection mechanism that kicked in because I tried to access my account while on holiday on the Canary Islands. I have heard horror stories of people loosing their email histories stored in Gmail and this little incident got me scared enough to investigate backing up my email history outside of Gmail.
I use a Synology NAS at home which has plenty of storage left to keep my roughly 2GB of email many times over. It has a variant of Linux installed and besides a nice web-based UI it has also the very handy ability to ssh into the box and install additional software through a package manager called ipkg.
Login to your NAS as root and install getmail with these commands:
ipkg update ipkg install python ipkg install py25-getmail
Now that your have the software installed pick a place where the email should be stored. I chose
/volume1/Gmail but any folder that is accessible to your ordinary user will do. Still logged in as root issue these commands:
The last one is necessary for the storage format (Maildir) and getmail doesn’t create these folders itself. Maildir stores each email in a separate file on the disk. If you want another storage format, read the getmail documentation.
Then create a file called
/volume1/Gmail/getmailrc with the following content, using your own username and password:
Now everything is in place for getmail to do its work. Do a test run with the following command to test if it will run into any problems.
This will start downloading your messages but depending on the size of your email history will take up to a few hours. There is the distinct probability that your ssh connection will time out and drop due to your inactivity. That’s why I ran the first go with nohup so that me logging out wouldn’t stop the process.
Lastly, we obviously want to run getmail periodically and fetch the newest message so open up
/etc/crontab with a text editor like vim (you probably need to install it with ipgk first) and add the following line:
(It is important so separate the individual parts of the crontab with a tab not a space as otherwise the Synology will delete your entry when you reboot.)
This will run getmail every Wednesday at 3AM when you’re sound asleep. The
/bin/su complication is necessary because it appears that the Synology cron can’t run jobs as non-root.
Also, on my Synology you have to restart the cron daemon for it to pick up the changes with a