text 使用rclone为Linux自动执行Google Drive同步

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 使用rclone为Linux自动执行Google Drive同步相关的知识,希望对你有一定的参考价值。

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

以上是关于text 使用rclone为Linux自动执行Google Drive同步的主要内容,如果未能解决你的问题,请参考以下文章