Storing files off-site with gmail

Posted by Steve on Fri 29 Jul 2005 at 02:18

gmail is the well-known webmail service from Google. Whilst I've never really used it for mail I do mount its storage space, remotely, upon my Debian machine and use it as another form of backup space.

The trick to doing this is the gmailfs package. This takes advantage of filesystem in userspace (fuse) project.

Fuse, as its name suggests, allows you to code a filesystem entirely in user-space - no kernel mode programming required. With a little bit of effort you can treat almost anything as a filesystem.

The gmailfs module allows you to treat GMail's storage space as a mountable filesystem. It is not the fastest thing on the world, and Google may well remove the ability to use it in the future, but right now it works nicely.

Other approaches to mounting remote systems include:

To get started you'll need to download and install the gmailfs package via apt-get (or aptitude):

root@sillyhostname:~# apt-get install gmailfs
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  fuse-utils libfuse2 python-fuse python-libgmail python2.3-fuse
Suggested packages:
  fuse-module
The following NEW packages will be installed:
  fuse-utils gmailfs libfuse2 python-fuse python-libgmail python2.3-fuse
0 upgraded, 6 newly installed, 0 to remove and 1 not upgraded.
Need to get 141kB of archives.
After unpacking 532kB of additional disk space will be used.
Do you want to continue [Y/n]? 

Once installed the package will prompt you, via debconf, which group should be given permission to run several commands. You may choose the default option for this question safely.

The next step is to build and install the fuse kernel module.

To do this you'll need to download the fuse-source package, along with module-assistant if you don't already have that installed.

The module-assistant package is a great tool to build kernel modules for Debian systems.

root@sillyhostname:# apt-get install fuse-source
Reading package lists... Done
Building dependency tree... Done
Suggested packages:
  kernel-package
The following NEW packages will be installed:
  fuse-source
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 83.7kB of archives.
After unpacking 127kB of additional disk space will be used.

Now that the packages are ready you can build the kernel module by executing the following three commands:

root@sillyhostname:~# module-assistant prepare
Kernel headers available in /usr/src/linux
Done!
root@sillyhostname:~# module-assistant build fuse
root@sillyhostname:~# module-assistant install fuse

This should build and install a package which contains the kernel module. To actually load the kernel module execute:

root@sillyhostname:~# modprobe fuse

If you receive an error message:

FATAL: Error inserting fuse : Invalid module format

This most probably means that the compiler you are using to build the kernel module doesn't match the one used to build the kernel you are running. You can discover the GCC version used to compile your kernel by running "cat /proc/version". A simple solution here to run the following commands, assuming that your kernel was built with gcc-3.3 as mine was:

root@sillyhostname:# cd /usr/src/modules/fuse/kernel
root@sillyhostname:# rm .*.cmd *.o *.ko
root@sillyhostname:# rm /usr/bin/gcc; ln -s /usr/bin/gcc-3.3 /usr/bin/gcc
root@sillyhostname:# module-assistant build fuse --force
root@sillyhostname:# module-assistant install fuse --force

Once you've successfully built and installed the kernel module you can start to mount your remote gmail space. (Don't forget you must have a gmail account already setup!)

To mount the filesystem you need four things:

The random string is very important. You must choose something random as a kind of key when mounting the remote system. If you choose something that somebody else can guess they are capable of messing up your filesystem by sending you malicious email.

To actually mount the filesystem first create a mount-point:

root@sillyhostname:~# mkdir -p /mnt/google

Then mount it with the following command:

root@sillyhostname:~#  mount -t gmailfs none /mnt/google -o username=username@gmail.com,password=Password,fsname=Key
root@sillyhostname:~# 
gmailfs.py:Gmailfs:mountpoint: '/mnt/google'
gmailfs.py:Gmailfs:unnamed mount options: ['rw']
gmailfs.py:Gmailfs:named mount options: {'username': 'username@gmail.com', 'password': 'password', 'fsname': 'key'}
INFO:gmailfs:Connected to gmail

Here I've used a bold font for the parts you should replace. Once you've ran this command you'll be returned to your prompt after a short delay. (Strangely I had to press 'Return' to get a prompt back...)

Now you can copy files to the mountpoint, /mnt/google, which will result in files being created remotely. You'll notice that the speed is much slower than a local access, but in all other respects it should work as a normal filesystem.

To disconnect the remote mount run:

umount /mnt/google

If you view your gmail webmail you will discover lots of "random" mail messages sent to yourself, from you. These are the contents of your filesystem - delete them and your file store will be gone!

If you wish you can setup the username and password in the file /etc/gmailfs/gmailfs.conf - this file allows you to store your gmail username, password, and key.

If you do store your connection details you can mount the system by executing simply:

root@sillyhostname:# mount.gmailfs none /mnt/google -o

All mount and unmount operations conducted over the gmailfs filesystem will be logged to the file /var/log/gmailfs, which can be used to diagnose errors. To increase the level of debugging information simply adjust the configuration file /etc/gmailfs/gmailfs.conf appropriately.

All in all the system allows a reasonably reliable system for storing non-essential backups. I'd be wary of trusting the storage too much, but if your files are non-critical have a blast!


This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2005 Steve - please ask for permission to republish or translate.