/av-tool-sync-to-remote

Sync local folders to a remote storage.

Primary LanguageShellMIT LicenseMIT

Sync to Remote

This shell script syncs local folders to a remote storage.

Requirements

  • Tested on MacOS Big Sur. Might work on other releases.

Todo

  • Make script self-updating on run
  • Move todo to GitHub project boards

Installation

Install the package manager Homebrew.

Install Rclone

brew install rclone

Configure Rclone

rclone config

Choose the following options for Google Drive:

  • menu option -> new remote
  • name -> gdrive
  • type -> drive (Google Drive)
  • client_id -> <Google Cloud Project - Google Drive API auth>
  • client_secret -> <Google Cloud Project - Google Drive API auth>
  • scope -> 1
  • root_folder_id ->
  • service_account_file ->
  • Edit advanced config -> no
  • Use auto config -> no
  • Configure this as a team drive -> no for 'my drive', yes for a shared drive

Usage

Run from the command line

./sync-to-remote.sh <command> [flags]

Use the command help to see an overview of available commands and flags.

Schedule using the launchd agent

Launchd is the recommended scheduling agent for MacOS.

When called by Launchd, rclone seems unable to access protected folders such as Desktop and Documents. User created folders, with identical user, group and rights do not suffer this problem. My request for assistance through the rclone forum, has been met with no response. See Schedule using Cront for a solution without this limitation.

When the computer is running on battery power, no scheduled sync takes place, unless forced by providing the backup command.

Make the project files accessible to all users of a machine by placing it in /Users/Shared. For a single user; a more limited location such as ~/Applications can be used.

By making a shallow clone of the git repository (using --depth 1), only the most recent changes are downloaded.

git clone --depth 1 https://github.com/averstuyf/av-tool-sync-to-remote.git /Users/Shared/av-tool-sync-to-remote/

In the future update the clone, overwriting any local changes.

cd /Users/Shared/av-tool-sync-to-remote
git fetch
git reset --hard origin/master

Make a symlink to the launchd agent config file in /Library/LaunchAgents for all users or ~/Library/LaunchAgents for a specific user.

sudo ln -s /Users/Shared/av-tool-sync-to-remote/com.av.sync-to-remote.plist /Library/LaunchAgents/com.av.sync-to-remote.plist

Have launchd load the agent.

launchctl load /Library/LaunchAgents/com.av.sync-to-remote.plist

See script output and errors.

cat /tmp/sync-to-remote.stdout
cat /tmp/sync-to-remote.stderr

Schedule using Cron

Edit the crontab config file using nano.

export VISUAL=nano; crontab -e

To run the script every 12 hours, add the following line. The && instead of ; prevents the script from being executed if the cd command fails.

0 0/12 * * * cd /Users/Shared/av-tool-sync-to-remote && /Users/Shared/av-tool-sync-to-remote/sync-to-remote.sh

License

This repository is licensed under the permissive MIT License.


Copyright (c) 2020 Arnaud Verstuyf.