Skip to content

Instantly share code, notes, and snippets.

@peterchester
Created July 16, 2014 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterchester/b917913c04ce1ee9e0e5 to your computer and use it in GitHub Desktop.
Save peterchester/b917913c04ce1ee9e0e5 to your computer and use it in GitHub Desktop.
Bash script for backing up selected google docs on a mounted google drive. Copies the files to new files with "BACKUP YYYY-MM-DD" added to the file name.
#! /bin/bash
# Google Drive path
BASEDIR='/Users/xxxx/Google Drive/'
# Files to backup
FILES=(
'Some Folder on Your Drive/Some Spreadsheet.gsheet'
'Some Other Folder on Your Drive/Some Doc.gdoc'
)
# Date appended to the file to mark it as a backup.
DATE=$(date '+%Y-%m-%d')
# Loop through files to back them up.
for i in "${FILES[@]}"; do
ORIGINALPATH="$BASEDIR$i"
BAREPATH=${ORIGINALPATH%.*}
EXTN=${ORIGINALPATH##$BAREPATH}
BACKUPPATH="$BAREPATH BACKUP $DATE$EXTN"
cp "$ORIGINALPATH" "$BACKUPPATH"
echo "Backup Complete: $BACKUPPATH"
done
@peterchester
Copy link
Author

I place this in my google docs root folder and can run it as follows:

bash /Users/xxxx/Google\ Drive/gdoc-backup.sh

I've also added this to my laptops cron:

crontab -e

Then I added the line:

0 10 1 * * /bin/bash /Users/xxxx/Google\ Drive/gdoc-backup.sh > /dev/null 2>&1

This runs at 10am on the first of every month.

@andrewferrier
Copy link

Maybe I'm missing something, but are you aware that .gsheet, .gdoc etc are just pointers to the files online? Look in those actual files and inspect the contents? I don't think this backup will help you much if Google Docs disappears/goes down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment