Skip to content

Instantly share code, notes, and snippets.

@jamcole
Last active June 26, 2024 20:02
Show Gist options
  • Save jamcole/5ccd9eb2ebfd1710d4bb891ac3c8d0b6 to your computer and use it in GitHub Desktop.
Save jamcole/5ccd9eb2ebfd1710d4bb891ac3c8d0b6 to your computer and use it in GitHub Desktop.
rclone backup google workspace drive folders, including shared drives, and shared with me
#!/bin/sh
# needs RCLONE_CONFIG env set
DRIVE_USERS="james@example.com rebecca@example.com"
ADMIN_USER="james@example.com"
REMOTE_SRC="drive:"
REMOTE_DEST="b2-crypt:"
RCLONE_CONFIG_DIR=$(mktemp -d)
cp -av "$(dirname "$RCLONE_CONFIG")/." "$RCLONE_CONFIG_DIR/"
cat "$RCLONE_CONFIG" > "$RCLONE_CONFIG_DIR/rclone.conf"
rclone backend drives --drive-impersonate=$ADMIN_USER -o config "$REMOTE_SRC" >> "$RCLONE_CONFIG_DIR/rclone.conf"
export RCLONE_CONFIG="$RCLONE_CONFIG_DIR/rclone.conf"
for u in $DRIVE_USERS; do
rclone sync "$REMOTE_SRC" --inplace --ignore-checksum --drive-impersonate=$u "$REMOTE_DEST/user/$u/My Drive" $@
rclone sync "$REMOTE_SRC" --inplace --ignore-checksum --drive-shared-with-me --drive-impersonate=$u "$REMOTE_DEST/user/$u/Shared with me" $@
done
if grep -E '^upstreams ?= ?["A-Za-z0-9]+' "$RCLONE_CONFIG"; then
rclone sync 'AllDrives:' --inplace --ignore-checksum --drive-impersonate=$ADMIN_USER "$REMOTE_DEST/shared-drives" $@
else
echo No Shared Drives to Sync
fi
[drive]
type = drive
scope = drive.metadata.readonly,drive.readonly
service_account_file = ${RCLONE_CONFIG_DIR}/sa/backup-sa.json
skip_shortcuts = true
acknowledge_abuse = true
[b2-crypt]
type = crypt
remote = b2:example-bucket
filename_encryption = off
suffix = .encrypted
# password was passed through rclone obscure
password = blah
[b2-crypt-versions]
type = crypt
remote = b2-versions:xrks-drive-backups
filename_encryption = off
suffix = .encrypted
# password was passed through rclone obscure
password = blah
[b2]
type = b2
account = blah_id
key = blah_key
[b2-versions]
type = b2
account = blah_id
key = blah_key
versions = true
@jamcole
Copy link
Author

jamcole commented Jun 26, 2024

I run this application as a Google Cloud Run Job, see screenshots below for configuration details

Screenshot-20240626134706-589x1194
Screenshot-20240626134646-566x1705

Google Drive Service Account was set-up following instructions at https://rclone.org/drive/#service-account-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment