Backup script on Google Drive for Linux

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.

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

  • Muito bom…

    • I’m not sure I follow your sugoestign, Duncan. The part of the script you are referring to is just part of the original cygwin bat shell written by whoever wrote cygwin. My modification is around getting cygwin to launch my shell script (the part after the -c switch), and then getting that shell script to figure out what directory it is in and change the working directory there.

  • Thanks a lot. It’s work and works great.
    Ubuntu 13.10
    I’ve installed by run
    $> apt-get install grive

    • 4 years agoHello Ray,I used ORCA, but this doesn’t work as expected. Also, most of the time Universal extcrator cannot extract anything from the MSi it doesn’t do a very good job.But I’m glad you posted something concrete. I am going to try this one.Have any idea if the author is going to update the Less MSIe9rables? By the name, I guess it’s a french author Thanks for this tip man. I hoped Microsoft would have given a tool of its own, but Thanks again.Reply

  • Thx.
    What about the bandwidth? If my backups are about 400 GB in size, it will also work with the upload and download of the Google Drive?

  • I ԛuite like reading ann articlе that can make men and women think.
    Also,thank yoou for permitting mme to comment!

    my webpage … [Shop Evo Design]( “Shop Evo Design”)

  • Great manual

    But I recommend better to change in the script a copying procedure to rsync.
    # Coping new content
    echo Copying from ${BACKUPDIR}/* to ${GDRIVEDIR}/${TARGETDIR}/
    # Coping new content
    echo Copying from ${BACKUPDIR}/* to ${GDRIVEDIR}/${TARGETDIR}/
    rsync -auz -r –delete ${BACKUPDIR}/ ${GDRIVEDIR}/${TARGETDIR}/

  • Finally i quit my regular job, now i earn a lot of money online you should try too, just search in google – blackhand roulette

  • sgitkene

    Hello, this doesn’t work as easily anymore. Google deprecated the api used here. Maybe you can get it to work with and supply a .deb package for it to easily work? The package in jessie uses the deprecated api and doesn’t work anymore.

  • Daniel Sobrinho

    nice script

  • LeoRS