In this article I will show you how to install Gmvault on a Synology Diskstation and have it back up your Gmail accounts. This will eliminate the need for your computer to be on and also saves processing power on your system, since everything is handled by the Diskstation.
Installing Python 2.7
The first set of steps will have us install Python 2 on the DiskStation, since it’s needed for Gmvault to run.
- Log into Synology NAS as an admin user (can be your own username if you are in the Administrators group) and go to Main Menu -> Package Center -> Settings and set Trust Level to Synology Inc. and trusted publishers.
- In the Package Sources tab, click Add, type “SynoCommunity” as Name and “https://packages.
synocommunity.com/” as Location and then press OK to validate.
- Go back to the Package Center and install the Python 2.7 package (“Python”) in the Community tab. (Synology provides Python 3, so if a later version of GMVault is made compatible then you won’t need to do steps 1-4).
- Remove the Package Source and reset the Trust Level to “Synology Inc.”
Set up Folders for Gmvault backups
We now have Python 2.7 installed. Nex,t we need to set up the folders to keep the backups in. Go to Control Panel -> Shared Folder. Create a new folder called Gmvault.
[Optional] You can also encrypt the contents of the folder by clicking the folder then clicking on the Edit button and then on the Encryption tab. Then click the checkbox next to Encrypt this shared folder and enter an encryption key.
Go to Control Panel -> Terminal & SNMP -> Enable SSH service.
If you have Security Advisor enabled it might complain about the SSH service not being secure if you use the default port of 22, which I didn’t bother changing as I was only logging in via my local network.
Installing Pip, the Python Virtual Environment and Gmvault
Open a Terminal window on your Mac and SSH into the Diskstation using a user with admin access.
Make sure you navigate your way to volume1 or whichever volume you will be using to set up Gmvault on and store the backups. In that volume, you should find the Gmvault folder we created earlier. Make sure you are in that directory then follow the next steps:
- wget https://bootstrap.pypa.io/get-pip.py
- sudo python
- sudo pip install virtualenv
- rm get-pip.py
- virtualenv gmvault_env
- cd gmvault_env
- sudo pip install gmvault
What we did above is to install the pip utility that is needed to install Python packages/modules, followed by installing virtualenv. Virtualenv is a tool to create isolated Python environments. It creates a folder which contains all the necessary executables to use the packages that a Python project would need. More info about it and how it works can be found here.
With those in place we created an environment for Gmvault and installed it using pip.
Setting up Gmvault
We are now at the stage where we already have Gmvault and can start having some fun with it.
To make sure that Gmvault has installed correctly, type in the following command:
- gmvault -h
This should display the help for Gmvault, if it does, you’re good to go. Follow the next steps:
- gmvault sync -t full –db-dir /volume1/Gmvault/backups/YOUREMAILADDRESS/ –emails-only –no-compression my_email…@gmail.com
- Gmvault will then prompt to open a web browser to grant OAuth2 access.
Press Enter to open the browser – which won’t happen!
- Highlight the web address that Gmvault displays.
- Open a new window in your web browser and paste the web address into the address bar.
- Login to Google Mail and grant access to Gmvault.
- Copy the authentication token that Google will display and paste into the SSH session.
That’s it! Gmvault should now continue and download the emails.
If you’re curious about the parameters I used when executing gmvault, have a look at the in-depth guide on the Gmvault site which details all the possible parameters.
Note: For security purposes, you can now disable the SSH service. It is recommended to only activate this service whenever you need it, especially if you make your Diskstation available over the internet.
While you can choose to encrypt using gmvault itself, however, I decided to use Synology’s own facility for encrypting folders. For more information about Synology’s encryption, you can refer to this article. The official Synology guide is also a handy reference, as is their page on managing keys.
There are additional steps you can take to improve this workflow, for example setting a recurring automated task that runs, say, on a daily basis. This would make the backups work without your intervention.
Have you set up automated backups for your Gmail accounts? What’s your take on the subject?