Hack for Archiving Google Drive

Problem: Archiving of Google Drive documents does not work with the google drive app. Why? Google Drive App stores only links to the cloud (i.e. .gdoc, .gsheet).
Solution: Write a script and use a cron job 🙂


#!/bin/bash
google_drive_dir="/home/my_user_name"
which gdrive >/dev/null || echo "Missing gdrive. Get it here: https://github.com/prasmussen/gdrive"
_archive_filetype ()
{
from=$1
to=$2
find "$google_drive_dir" -name "*.$from" -print0 | while read -d $'\0' file
do
id=$(sed 's/.*"doc_id": "//;s/".*//' "$file")
bd=$(dirname "$file")
cd "$bd"
gdrive download --id $id --format "$to" --force
done
}

_archive_filetype gdoc docx
_archive_filetype gslides pdf
_archive_filetype gsheet xlsx

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s