How to back up your Gmail/G Suite emails on a Synology NAS
This weekend I reviewed my email backup strategy and decided to make daily backups of all my accounts directly on my NAS. Since they are all Google-based, I went with
gmvault on my Synology server. Here’s a walkthrough.
There are posts online that achieve this using
ipkg and compiling dependencies. As of this writing (DSM v6), this is no longer needed.
Note: I’m using the
rootaccount because I am the only user of that server. Also, this lets me set up a crontab without reloading the cron service between shutdowns and reboots, due to Synology’s peculiar cron management system. Keep this in mind if you are on a shared NAS.
Make sure you checked the Gmail setup beforehand.
Log onto DSM, and install Python via the Package Manager.
Enable SSH in the Control Panel, under “Terminal & SNMP”.
Open a terminal and log in via SSH. You will be prompted for your password.
Switch to root. Use your password again:
Download and install the Python Package Index:
wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py
Remove the pip setup script, and install
rm get-pip.py && pip install gmvault
Create a folder to store the backups, otherwise they’ll go to
gmvault. Notice the
--emails-onlyoption since I don’t care about chats, and
-dflag with my custom backup path:
gmvault sync firstname.lastname@example.org --emails-only -d /volume1/gmvault/your_account\@gmail.com/
It will run for a while now. Repeat steps 7 and 8 if you have multiple accounts.
Automated backups with cron
Now, let’s set up a cron job to have daily backups.
Open the crontab:
Edit the crontab. For daily/weekly backups you can use
-t quick. Note that entries must be delimited by tabs. This will run daily at 2AM :
0 2 * * * root gmvault sync email@example.com --resume -t quick --emails-only -d /volume1/gmvault/your_account\@gmail.com/
Save your crontab and restart the cron service:
synoservice -restart crond
You’re all set!
Update (May, 25th 2018): A previous version of this article included a crontab that ran every minute for an hour, instead of once at a given hour. Thanks Kristian for the tip!