Created
April 1, 2020 12:37
-
-
Save mrsrvman/bb6a669c117c1de3dfc29267399b684d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Script that will trigger a local to remote sync when any changes below your local Google Drive folder occur - but at max. every 10 minutes - and a remote to local sync every x (e.g. 30 minutes) via a cron job. | |
0. Install rclone and configure it for Google Drive | |
1. Create files listed below | |
2. Configure rclone_watch_local.sh to be run on startup (e.g. using a systemd service unit) | |
3. Add a cron job that runs rclone_remote2local.sh every x (e.g. 30) minutes | |
---------------------- | |
rclone_local2remote.sh | |
---------------------- | |
!/bin/bash | |
GDRIVE_DIR=/media/myuser/HDD/Google\ Drive | |
echo '[rclone] Syncing local -> remote.' | |
if [ -d "$GDRIVE_DIR" ]; then | |
if ! ps ax | grep -v grep | grep "rclone sync" > /dev/null; then | |
rclone sync "$GDRIVE_DIR" drive:/ && echo 'Finished local -> remote sync.' | |
else | |
echo '[rclone] A sync is already running.' | |
fi | |
fi | |
---------------------- | |
rclone_remote2local.sh | |
---------------------- | |
!/bin/bash | |
GDRIVE_DIR=/media/myuser/HDD/Google\ Drive | |
echo '[rclone] Syncing remote -> local.' | |
if [ -d "$GDRIVE_DIR" ]; then | |
if ! ps ax | grep -v grep | grep "rclone sync" > /dev/null; then | |
rclone sync drive:/ "$GDRIVE_DIR" && echo '[rclone] Finished remote -> local sync.' | |
else | |
echo '[rclone] A sync is already running.' | |
fi | |
fi | |
--------------------- | |
rclone_watch_local.sh | |
--------------------- | |
!/bin/bash | |
GDRIVE_DIR=/media/myuser/HDD/Google\ Drive | |
echo '[rclone] Watching locally.' | |
if [ -d "$GDRIVE_DIR" ]; then | |
while true; do | |
# sync at max every 10 minutes | |
inotifywait -r "$GDRIVE_DIR" && bash /home/myuser/scripts/rclone_local2remote.sh && sleep 10m | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't your recommended setup (systemd unit + cron job every 30 minutes) potentially impose conflicts?
Do you have a recommendation to make sure the current state is fetched after a restart?
I think this would work fine
Additionally I think
inotify
should only watch for theclose_write
event, because it otherwise gets triggered byrclone_remote2local.sh
.