Skip to content

Instantly share code, notes, and snippets.

@aadm
Created April 18, 2018 14:56
Show Gist options
  • Save aadm/38158e8be5bbf4a874d61a8d2481fd50 to your computer and use it in GitHub Desktop.
Save aadm/38158e8be5bbf4a874d61a8d2481fd50 to your computer and use it in GitHub Desktop.
Google Drive sync with rclone
#!/bin/bash
# script to sync Google Drive with local folder using rclone
# modified from initial version that used rsync and a usb disk
# by default will write log to home directory with name sinc_gdrive_log.txt
# check also exclusion list
# usage:
#
# $ sinc_gdrive.sh [command]
#
# command:
# PUSH to push changes to cloud (from local to Google Drive)
# PULL to pull changes from cloud (from Google Drive to local)
# no command runs the script in dry-run mode to preview changes in both directions
#
# (C) AAdM 2016-2018
time_start=$(date +"%Y/%m/%d %H:%M:%S")
time_start_sec=$(date +%s)
LOGFILE=$HOME/sinc_gdrive_log.txt
if [ "$1" == "PUSH" ]; then
textred "$time_start [sinc_gdrive.sh] PUSH home >> googledrive"
echo "$time_start [sinc_gdrive.sh] PUSH home >> googledrive" >> $LOGFILE
rclone sync GOOGLEDRIVE gdrive: --drive-skip-gdocs --update --transfers=20 --checksum -v --stats=0 --log-file=$LOGFILE --exclude={~*,._**,.git/,__pycache__/}
elif [ "$1" == "PULL" ]; then
textred "$time_start [sinc_gdrive.sh] PULL home << googledrive"
echo "$time_start [sinc_gdrive.sh] PULL home << googledrive" >> $LOGFILE
rclone sync gdrive: GOOGLEDRIVE --drive-skip-gdocs --update --transfers=20 --checksum -v --stats=0 --log-file=$LOGFILE --exclude={~*,._**,.git/,__pycache__/}
else
textcya "$time_start [sinc_gdrive.sh DRY-RUN] PUSH home >> googledrive"
rclone sync GOOGLEDRIVE gdrive: --drive-skip-gdocs --update --transfers=20 --checksum --dry-run --exclude={~*,._**,.git/,__pycache__/}
textcya "$time_start [sinc_gdrive.sh DRY-RUN] PULL home << googledrive"
rclone sync gdrive: GOOGLEDRIVE --drive-skip-gdocs --update --transfers=20 --checksum --dry-run --exclude={~*,._**,.git/,__pycache__/}
fi
time_end=$(date +"%Y/%m/%d %H:%M:%S")
time_end_sec=$(date +%s)
stat_time=$((time_end_sec - time_start_sec))
if [ $stat_time -lt 60 ]; then
stat_time="$stat_time seconds"
elif [ $stat_time -lt 3600 ]; then
stat_time="$((stat_time / 60)) minutes and $((stat_time % 60)) seconds"
else
stat_time="$((stat_time / 3600)) hours and $(((stat_time % 3600) / 60)) minutes"
fi
textwhi "$time_end [sinc_gdrive.sh] elapsed time: $stat_time"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment