Automated backup script for multiple Google Drive accounts to external storage volumes, with optional macOS automation.
Before using this script:
- Configure your actual rclone remote names
- Never commit personal remote names or credentials
- Review logs before sharing (may contain file paths)
brew install rclone
# or download from https://rclone.orgrclone configFollow the prompts to set up your Google Drive remotes. Choose meaningful names like:
work_drivepersonal_drivebackup_account
Edit the script to set your remote names, or use environment variables:
# Option A: Edit the script defaults
REMOTE_1="${REMOTE_1:-work_drive}"
REMOTE_2="${REMOTE_2:-personal_drive}"
# Option B: Use environment variables (recommended)
export REMOTE_1="work_drive"
export REMOTE_2="personal_drive"Note: The script refuses the default placeholders (remote1/remote2). Set real remote names or export ALLOW_DEFAULT_REMOTES=1 for temporary testing. Remote names must match [A-Za-z0-9_-].
- ✅ Backs up multiple Google Drive accounts
- ✅ Backs up both your own files AND files shared with you
- ✅ Organizes shared files in dedicated "Shared_with_me" subfolders
- ✅ Automatic external volume detection (Archives-A/Archives-B)
- ✅ Disk space validation
- ✅ Export Google Docs/Sheets/Slides to Office formats
- ✅ Comprehensive logging and error reporting
- ✅ Snapshot versioning with automatic cleanup
- ✅ Test mode for safe initial runs
- ✅ Continues backup even if one drive fails
- ✅ Automated backup monitoring with macOS notifications
The script creates this folder structure on your external drive:
/Volumes/Archives-A/
├── work_drive/
│ ├── (your personal files and folders)
│ └── Shared_with_me/
│ └── (files shared with you)
├── personal_drive/
│ ├── (your personal files and folders)
│ └── Shared_with_me/
│ └── (files shared with you)
└── _logs/
└── (backup logs organized by timestamp)
REMOTE_1="work_drive" REMOTE_2="personal_drive" MODE=test ./run_gdrives_backup.shREMOTE_1="work_drive" REMOTE_2="personal_drive" ./run_gdrives_backup.shFor automated daily backups, you can set up a macOS LaunchAgent:
- Open Automator and create a new Application
- Add "Run Shell Script" action
- Set the script to run your backup command
- Save as
RunGDrivesBackup.appin/Applications/
# Copy the example plist and customize it (kept local and gitignored)
cp com.user.googledrive.backup.plist.example com.user.googledrive.backup.plist
# Edit the plist file to match your setup:
# - Update the path to your Automator app
# - Update user paths (WorkingDirectory/StandardOutPath/StandardErrorPath)
# - IMPORTANT: Set RunAtLoad to true for auto-start on boot
# Install into LaunchAgents (prefer a copy; symlinks can break if the repo is iCloud-managed)
cp com.user.googledrive.backup.plist ~/Library/LaunchAgents/
# Load it (will run immediately and then daily at 23:00)
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.user.googledrive.backup.plistImportant Configuration:
- Set
<key>RunAtLoad</key><true/>in the plist to ensure the backup service automatically starts after system reboots - Without this setting, backups will stop running after a reboot until manually reloaded
# Check status
launchctl list | grep googledrive
# Stop the service
launchctl bootout gui/$(id -u)/com.user.googledrive.backup
# Restart after system reboot or if service stops (should happen automatically, but if needed):
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.user.googledrive.backup.plist
# View logs
tail -f ~/Library/Logs/com.user.googledrive.backup.stdout.logThe monitor_backup.sh script checks if backups are running successfully and sends macOS notifications.
# Make the script executable
chmod +x monitor_backup.sh
# Test it manually
./monitor_backup.sh check # Check status and send notification
./monitor_backup.sh summary # Display backup summary report
# Install automated monitoring (runs daily at 9 AM)
# Copy the example plist and customize it (kept local and gitignored)
cp com.user.googledrive.backup.monitor.plist.example com.user.googledrive.backup.monitor.plist
# Edit the plist file to match your setup:
# - Update the script path in ProgramArguments
# - Update user paths (WorkingDirectory/StandardOutPath/StandardErrorPath)
# NOTE: Ensure RunAtLoad is set to true in the plist for auto-start on boot
cp com.user.googledrive.backup.monitor.plist ~/Library/LaunchAgents/
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.user.googledrive.backup.monitor.plistBy default, the monitor looks for Automator logs in ~/Library/Logs/Backups/automator-*.log. If you run backups another way, update BACKUP_LOG_DIR near the top of monitor_backup.sh.
The monitoring script will send macOS notifications for:
- ✅ Success: Backup completed successfully
- ❌ Failure: Backup encountered errors
⚠️ Warning: Backup hasn't run in 26+ hours- ⏳ Running: Backup is currently in progress
| Setting | Default | Description |
|---|---|---|
MAX_AGE_HOURS |
26 | Alert if last backup is older than this |
Monitor logs are saved to:
~/Library/Logs/backup_monitor.log- Monitoring activity log~/Library/Logs/backup_last_status.txt- Latest backup status~/Library/Logs/com.user.googledrive.backup.monitor.stdout.log- LaunchAgent stdout~/Library/Logs/com.user.googledrive.backup.monitor.stderr.log- LaunchAgent stderr
The script is designed to be resilient:
- If backing up your personal files fails, it will still attempt to backup shared files
- If one Google Drive account fails, it will continue with the next one
- All errors are logged and reported at the end
- The script provides clear exit codes for automation
| Setting | Default | Description |
|---|---|---|
CHECKERS |
8 | Number of parallel file checks |
TRANSFERS |
8 | Number of parallel transfers |
RETENTION_DAYS |
90 | Days to keep old snapshots |
MIN_FREE_SPACE_GB |
50 | Minimum required free space |
- 🔒 Never commit rclone config files
- 🔒 Use environment variables for sensitive configuration
- 🔒 LaunchAgent plist files contain personal paths - keep them out of git
- 🔒 Regularly review and rotate access tokens
- 🔒 Review log files before sharing
- 🔒 Use specific, non-personal remote names in public examples
- "Cannot access remote" error: Check
rclone config show - Permission errors: Verify Google Drive API access
- Network timeouts: Check internet connection
- Disk space errors: Free up space on destination volume
- LaunchAgent not running after reboot: Ensure the plist in
~/Library/LaunchAgents/is a real file (not a symlink),RunAtLoadis true, and reload it (see below) - "can't open input file" for
monitor_backup.sh: Verify the script path in the plist and ensure the repo is kept downloaded if it lives in iCloud-managed~/Documents
launchctl bootout gui/$(id -u)/com.user.googledrive.backup 2>/dev/null || true
launchctl bootout gui/$(id -u)/com.user.googledrive.backup.monitor 2>/dev/null || true
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.user.googledrive.backup.plist
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.user.googledrive.backup.monitor.plist
launchctl list | grep -E "googledrive|backup"Optional diagnostics if it still fails:
launchctl print gui/$(id -u)/com.user.googledrive.backup | head -40
launchctl print gui/$(id -u)/com.user.googledrive.backup.monitor | head -40Logs are saved to <destination>/_logs/<timestamp>/:
main.log- Combined output from entire backup session<remote1>.log- First remote backup log (both personal and shared files)<remote2>.log- Second remote backup log (both personal and shared files)