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.
Enabling SSH
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 get-pip.py
- 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.
Encryption
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.
Further Improvements
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?
Peter says
Hi there! I have been using Gmvault for a long time. Suddenly, it stopped working (maybe related to a Synology update) and I re-installed. However, could not connect any more via oauth and received “This app is blocked” when trying to re-initialize. I used then -p with an app password, but when the script tries to connect to the server I just get:
Error when reaching Gmail server. Wait 1 second(s) and retry up to 2 times.
Disconnecting from Gmail Server and sleeping …
Reconnecting to the from Gmail Server.
Error when reaching Gmail server. Wait 2 second(s) and retry up to 2 times.
Disconnecting from Gmail Server and sleeping …
Reconnecting to the from Gmail Server.
Error when reaching Gmail server. Wait 4 second(s) and retry up to 2 times.
Error: command: UID => got more than 1000000 bytes.
Anybody else experiencing the same?
adam says
I keep receiving “error: argument -m/–multiple-db-owner: ignored explicit argument ‘ails-only'” when executing gmvault sync -t full –db-dir /volume1/Gmvault/backups/YOUREMAILADDRESS/ –emails-only –no-compression my_email…@gmail.com
Adam says
Thanks for the instruction. I was able to follow every step until I stumbled upon gmvault sync -t full –db-dir /volume1/Gmvault/backups/YOUREMAILADDRESS/ –emails-only –no-compression my_email…@gmail.com
I am confused as to whether YOUREMAILADDRESS is the same as my_email…@gmail.com
Let’s suppose my_email…@gmail.com is actually [email protected]. What should be the correct syntax for the above? Thanks.
Russell says
you shouldn’t use sudo with pip. in this case, you’re needing to use sudo because the virtual environment isn’t actually being utilized here; therefore, sudo is needed to install gmvault in to the system’s python environment.
To activate the virtual environment, source the activate script.
> source gmvault_env/bin/activate
Bart says
gmvault has been blocked by Google so don’t bother trying.
Christian says
Hi!
Any Updates on the automation? When i set up a task in dsm IT seems that i have to do the Authentication step again, but there is no interactive mode.
Christian says
Hi!
I have solved the problem by using a docker container that backups to data periodically to my Diskstation. For more than one account I deploy multiple container.
Jean says
Thanks for sharing Christian.
Jerry says
You are my hero Jean!
A couple comments to assist anyone who may attempt this:
– I had to enable user home service.
– I had to use sudo for “pip install gmvault”
Jean says
Thanks Jerry, added the modification in case others run into the same problem.
Avatar says
This was helpful – thank you!
Mini feedback:
* 1. wget https://bootstrap.pypa.io/gepipt-pip.py
This has to be https://bootstrap.pypa.io/get-pip.py
* 7. pip install gmvault
For me this only worked with sudo due to missing rights
* gmvault sync -t full –db-dir /volume1/Gmvault/backups/YOUREMAILADDRESS/ –emails-only –no-compression my_email…@gmail.com
This should have “–” in front of db-dir instead of just “-”
Thanks again. Today too many people don’t take the time to document their approach and help others. Much appreciated that you took the time.
Jean says
You’re welcome Bartel, I will update the post accordingly.
Mike says
Your article says – “At this point you will realise that we haven’t yet automated anything, and the automation part is an essential reason of why we’re doing this thing, so let’s proceed with getting that in place too.” and then pretty much ends?????
Jean says
That sentence was left in there by mistake, I now removed it. I haven’t yet gotten around to automate the process as I had some issues when setting it up, but it’s on my todo list. Any tips on how to do that would be great.
Ron says
Hello Jean!
I stumbled onto your page, attempting to find a method of constant gmvault backups, as my last solution unexpectedly stopped working (and I can no longer find the resource I used to set it up).
During the pip install (the step “wget https://bootstrap.pypa.io/gepipt-pip.py“), I am met with a 404 error “Not found”. I thought it was a spelling error on the ‘gepipt-pip.py’ section, but attempting random combinations yielded the same error.
Would you happen to know another source for this material?
Thanks in advance!
Doc Rock says
edit line to getpip-pip.py
DocRock says
correction
should read https://bootstrap.pypa.io/get-pip.py
Jean says
Thanks, fixed.