How to Back Up Files to Google Drive on Linux

Gdfuse Featured Image

Google Drive is an excellent medium for people who need to store online copies of their files. Linux users can leverage its free 15 GB plan for backing up essential configuration files. Moreover, you can back up a large volume of data, including media files, if you have an active Google Workspace (formerly G-Suite) plan. This guide will show how you can automatically back up files to Google Drive in Linux using the open-source package google-drive-ocamlfuse and CRON.

What is google-drive-ocamlfuse?

google-drive-ocamlfuse is a FUSE filesystem that lets users mount their Google Drive storage on the local machine. It is written using OCaml and is freely available via GitHub. Some of its main features include full read/write access, multiple account support, Unix permissions, and Team Drive support.

How to Use It for Automatic Backups?

The first step is to mount the remote Google Drive to the local filesystem. This is where google-drive-ocamlfuse comes into play. Then we can use an automatic scheduler for periodically transferring files to the drive. To keep things simple, we’re using the Linux CRON utility to take care of the scheduling process. (You can use Zeit to schedule cron jobs, too.)

Install and Configure google-drive-ocamlfuse

First, we need to install google-drive-ocamlfuse on our Linux machine. Luckily, it is very straightforward. Fire up your terminal and enter the following command at the prompt.

adding gdfuse ppa

It will add the required package to your package manager’s repository list. You can go ahead and install the package by using the following commands.

installing gdfuse

Wait until the installation finishes. Once it completes, you need to configure it for mounting. The first step for this is to create a mount point for Google Drive in your local filesystem. You can do this by typing the below command in your terminal.

creating mount point to store backup files to google drive

Next, mount the drive storage with the following command:

mounting google drive

google-drive-ocamlfuse will open your default browser and redirect to the account authentication page for Google Drive. Select the account you want to mount locally.

selecting drive account

Enter the password for the selected account to authenticate yourself.

authenticating google account

Next, Google will require permission to grant access to google-drive-ocamlfuse. Click on “Allow” and proceed to the next page.

allowing gdfuse access to store backup files to google drive

You will be asked to allow access to your user account one more time.

allowing account access

Once you allow permission, it will redirect you to the webpage of google-drive-ocamlfuse. Congratulations, you’ve successfully mounted your Google Drive account to the local filesystem.

completed mount

Now is a good time to verify whether the mounting process for Google Drive went smoothly or not. If this stage gives an error, you can’t use it to back up files to Google Drive. Use the below command to verify this.

checking mount status

The output should display a list of files and directories present in your Google Drive storage. If everything goes as expected, we can proceed to configuring the backup scheduler.

Back Up Files to Google Drive Using CRON

A backup is nothing but a copy operation. Since our Google Drive is already mounted, we can copy files to it as part of the local filesystem. You can verify this by running the following command:

It should copy the test file to your drive storage. Use the ls command to verify whether it was successfully copied to Google Drive.

testing backup files to google drive using gdfuse

Now that everything is in place, configure cron for automating the backup process. If you don’t know already, cron is a scheduler that allows users to run certain commands periodically. We can specify which commands to run and when to run them by using the crontab. You can learn more about it here.

We’re using the following crontab entry to copy our “/tmp” folder’s contents to Google Drive at 00:00 daily.

If you want to back up your files once every week, use the following crontab entry.

It will copy the contents of “/tmp” to your drive storage at 00:00 of every Sunday. Replace “/tmp” with the directory containing your personal files. However, there is one last step. None of the above crontab entries mount Google Drive automatically. One quick solution to this is to mount the drive storage using another crontab entry, then follow it up with the entry for backup.

As you can see, we are mounting the drive five minutes earlier. It gives cron enough time to make sure it doesn’t miss the backup process due to initialization issues. Use the below command to edit the crontab and add the above lines.

crontab entries for storing backup files to google drive

Wrapping Up

We have presented a simple way to back up files to Google Drive using google-drive-ocamlfuse and cron. Alternatively, if you are using Gnome, you can also easily connect Google to your desktop and mount Google Drive on your system. You can also check out some other Cron alternatives or use the systemd timers as a cron replacement.

Rubaiat Hossain Rubaiat Hossain

Rubaiat is a CS graduate who possesses hands-on experience with Unix Administration, Web Programming, DevOps, and Virtualization. He has a strong passion for enlightening people in open-source technologies.


  1. Hi!
    You can delete it using “sudo apt remove google-drive-ocamlfuse”
    To delete the PPA use “sudo add-apt-repository –remove ppa:alessandro-strada/ppa”

  2. Will copying the entire Linux system cause an issue? If I wanted to copy everything down to the root? I am on Linux Mint 20.1. If this is okay, is this the proper syntax? 0 0 * * * cp / ~/mount/google-drive/
    Also, I tried 0 0 * * * cp /myfilename/ ~/mount/google-drive/ and it said 0: command not found Also, are there spaces between the 0s and the *s?

  3. I must apologize, I read through the cron link you posted, but now I have another issue. I have posted in my GNU nano 4.8 Cron file the following :
    @daily cp / ~/mount/google-drive/
    55 23 * * 0 google-drive-ocamlfuse ~/mount/google-drive
    @daily cp / ~/mount/google-drive/

    I don’t understand how to save this process and exit the terminal. It says there is a process still running. Is this the right syntax to back up the entire system including root? Would that even be safe?

  4. I tried this however, it just seemed to take forever. It is very slow. In the end I had to unmount Googledrive. I am using LM 20 and a router to get to the Internet. I’ll have a look at your other systems.

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.