Regular backups using Grive2 on Ubuntu

 Posted by:   Posted on:   Updated on:  2023-01-07T21:23:20Z

Free Google Drive backups on Ubuntu Linux with Grive2. By using crontab, regular backups can be made of any files and folders you want.

Grive is a Google Drive client for Linux that can do two-side synchronization between Google Drive and a local folder. The synchronization is done whenever the user launches the application, either from a launcher or from command line (it is a CLI application).

By adding grive to crontab, periodic backups of important folders can be made. And no user interaction is required because the process is automated. Here is how to do it in Ubuntu. There is no system load when the process is not running, but this comes with a disadvantage: no filesystem monitoring. Any updates are made during the automatic execution of Grive.
Regular backups using Grive2 on Ubuntu


The original grive development has been discontinued and it no longer works with the current Google Drive API. A fork named Grive2 can be installed from WebUpd8 repository. Open a Terminal and run the following commands:
sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install grive
Now choose a directory to backup. You must have read/write permissions. I recommend Documents folder. Unfortunately, only one folder can be chosen for backup. While in Terminal cd to that directory. If it is Documents, run cd ~/Documents. Now run Grive: grive -a. The -a argument tells Grive to request the authorization code from Google. This is what you'll see in Terminal:

Grive authentication terminal screenshot
Grive authentication
Open that link in browser, log in with your Google Account and if you allow Grive to access your Drive contents, a token will be generated. Copy and paste this code in Terminal. Note that in Terminal there is no Ctrl+V command. You'll have to right-click and select Paste. Now Grive will start the synchronization process. If you have a lot of files and/or a low speed internet connection it may take a while.

Whenever you want to do a manual synchronization you can use one of the methods:

  • cd to the folder you backup and simply run grive.
  • run grive in any folder with an argument: grive --path /home/<username>/Documents.


Grive won't do backups unless you run it. But being a CLI application which requires no user input to start the backup it can be run from a scheduled task. Instead of manually editing the crontab file, I chose the GUI solution: GNOME Schedule. Install it with sudo apt-get install gnome-schedule. Run it from Dash or from Terminal (gnome-schedule). On the main window, click the drop-down arrow next to New and add a Recurrent Task.

Gnome Schedule New Task menu screenshot

Make it run every week (or how often you want). The command is:
grive --path /home/<username>/Documents
Gnome Schedule New Task dialog screenshot

Click the Add button. Now, to test the task, click the Run button in the main window and ignore any warnings.

Gnome Schedule test task (Run) screenshot

If you see something like in the below screenshot, everything worked good.

Grive console output screenshot

If Grive starts synchronizing again all files and uploads other files than you know you have in the selected folder, it means you got the path wrong. Check again the command and use absolute paths.

Now that everything works, you might want to suppress output from Grive. Edit the task as follows:

Gnome Schedule task edit dialog screenshot

What cloud backup solutions do you use on Ubuntu? Have you tried this? 


No comments :