Backup script on Google Drive for Linux

The problem

With 5Gb of free space, Google Drive could be a good option for simple backups of small servers and desktops.

We'll use Grive for Google Drive support and a small script that you can adjust for your needs.

! This is an old article (2013). Maybe the content is outdated.

Installing Grive

On Debian:

apt-get install grive

On Ubuntu:

We'll be using PPA Repositories.

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install grive


Create a directory and enter it:

mkdir /mnt/GoogleDrive
cd /mnt/GoogleDrive

Run the grive command with the option -a to prepare and get authorization:

# grive -a
Please go to this URL and get an authentication code:

Please input the authentication code here:

Copy and paste the link into your browser, being sure to be logged on the right Google Account to access the Drive you need. Copy and paste back the authentication code, and is done - first sync will be done.

Warning: only "real" files will be synced - grive doesn't support download of Google Apps editable docs.


This script reads a directory to sync with GoogleDrive.

Create the following script in /SOMEPATH/ and give it permission to execute (chmod 755 /SOMEPATH/

# Google Drive Sync
# Author: Rafael Goulart <>
# Config BEGIN
# =====================================================================

# Directory to backup

# Google Drive directory

# Directory target in remote

# =====================================================================
# Config END

# Create backup dir if not exists
echo Creating ${GDRIVEDIR}/${TARGETDIR} if needed
if [ ! -d "${GDRIVEDIR}/${TARGETDIR}" ]; then mkdir ${GDRIVEDIR}/${TARGETDIR}; fi

# Moving to Gdrive Dir
echo Entering ${GDRIVEDIR}

# Initial sync
echo Initial Google Drive Sync

# Coping new content
echo Copying from ${BACKUPDIR}/* to ${GDRIVEDIR}/${TARGETDIR}/

# Showing files copied
echo Files to sync

# Final sync
echo Final Google Drive Sync

You have 3 parameters:

  • BACKUPDIR: Directory to backup - put your stuff here, make a script to compact your data befoe - default /var/backups
  • GDRIVEDIR: Google Drive directory you'd created before - default /mnt/GoogleDrive
  • TARGETDIR: Directory target in remote, it will be crated to not mess up your Drive - default /backups

Put this file in your crontab:

ln -sf /SOMEPATH/ /etc/cron.dayly/

or run it manually:


Warnings and Tips

  • Be aware of the limitations of Grive
  • You can save some disk space doing your backup directly on /mng/GoogleDrive/backups and only running grive after doing it. I prefered the 2 steps as suggested, but it's up to you


If the following command does not exist (Ubuntu 12.04)

sudo add-apt-repository ppa:nilarimogard/webupd8

install with:

sudo apt-get install python-software-properties