backupBSDFilesToGoogleDocs.sh 876 Bytes
#! /usr/local/bin/bash
BACKUPDIR=/backups/
GDRIVEDIR=/mnt/GoogleDrive

if [[ "$1" == "" ]]; then
	echo "Requires files to be specified. Exiting..."
	exit
fi
GDRIVETARGETDIR="$1"

ATTEMPTCOUNTS=0
while [[ "$ATTEMPTCOUNTS" -le 2 ]]; do
	if [[ ! -d "$GDRIVEDIR/$GDRIVETARGETDIR" ]]; then
		if [[ "$ATTEMPTCOUNTS" -eq 2 ]]; then
			echo "Attempt to mount failed $ATTEMPTCOUNTS times. Exiting..."
			exit
		fi
		echo "Google Drive not mounted, attempting to mount..."
		cd "$GDRIVEDIR"
		echo "Attempting to mount Google Drive..."
		grive -f
		mkdir -p "$GDRIVEDIR"/"$GDRIVETARGETDIR"
	else
		if [[ "$ATTEMPTCOUNTS" -eq 2 ]]; then
			echo "Mounted and synchronized from Google Drive..."
		fi 
	fi
	((ATTEMPTCOUNTS += 1))
done

echo "Ready to backup..."
cd "$GDRIVEDIR"
echo "Copying files..."
cp -r "$BACKUPDIR"/* "$GDRIVEDIR"/"$GDRIVETARGETDIR"
grive
echo "Backups complete"
exit