A small wrapper that configures recurring backups of a Linux directory
(default: $HOME) to Google Drive using rclone, and installs a user-level
cron entry to run it on a schedule.
rsync itself can't talk to Google Drive. This project uses rclone sync,
which provides rsync-like semantics and has a proper Drive backend with OAuth.
bash4+rclone(https://rclone.org/install/)cron(any standard Linux distro)flock(optional; prevents concurrent runs if present)
If rclone is missing, both the setup wrapper and the generated runner will
print a clear error with install instructions and exit non-zero.
Clone or copy the repo, then run the wrapper:
./setup-gdrive-backup.sh --configure
--configure drops you into the interactive rclone config flow once to set
up the OAuth token. After that the token lives in ~/.config/rclone/rclone.conf
(mode 600) and the cron job runs headless.
./setup-gdrive-backup.sh [options]
| Option | Default | Description |
|---|---|---|
-s, --source PATH |
$HOME |
Directory to back up |
-r, --remote NAME |
gdrive |
rclone remote name |
-d, --dest PATH |
backups/<hostname>/<basename> |
Path on the remote |
-c, --cron "EXPR" |
"0 2 * * *" |
Cron schedule |
--configure |
Launch interactive rclone config |
|
--bwlimit RATE |
Pass --bwlimit to rclone (e.g. 20M) |
|
--no-cron |
Generate runner but skip cron install | |
--uninstall |
Remove cron entry and runner | |
--dry-run |
Print actions without changing anything |
Example:
./setup-gdrive-backup.sh --configure \
--source "$HOME" \
--remote gdrive \
--dest "backups/$(hostname -s)/home" \
--cron "0 2 * * *" \
--bwlimit 20M
The wrapper is idempotent. Re-running with new options regenerates the runner
and rewrites the managed cron line (tagged # gdrive-backup managed entry).
| Path | Purpose |
|---|---|
~/.local/bin/gdrive-backup.sh |
Generated backup runner |
~/.config/gdrive-backup/config |
Saved parameters |
~/.local/state/gdrive-backup/backup.log |
Rotating log (10 MiB cap) |
~/.local/state/gdrive-backup/.lock |
flock lockfile |
All per-user. No sudo required.
- Sources the saved config
- Rotates the log if it's over 10 MiB
- Acquires a
flockso concurrent runs no-op - Calls
rclone syncwith sensible defaults:--fast-list,--transfers 4,--checkers 8,--tpslimit 10--drive-chunk-size 64M- Excludes
.cache, Trash,node_modules, git pack files,*.tmp,.DS_Store
- Logs success or non-zero exit with a timestamp
rclone sync is destructive on the remote: files deleted locally are deleted
on Drive. If you want to keep deletions around, change sync to copy in
the runner, or add --backup-dir to shuffle removed files into a dated
folder on Drive.
Cron uses a minimal $PATH. The generated runner checks $PATH plus
/usr/local/bin, /usr/bin, and ~/.local/bin for rclone. If you put
rclone somewhere else, edit the runner to call it by absolute path.
Backing up an entire $HOME is rough on Drive's per-file API quotas if you
have lots of small files. The exclude list handles common offenders. For dev
directories with millions of small files, point --source at something
narrower like ~/Documents.
./setup-gdrive-backup.sh --uninstall
Removes the cron entry and ~/.local/bin/gdrive-backup.sh. Config and logs
are left in place; remove them manually if you want them gone:
rm -rf ~/.config/gdrive-backup ~/.local/state/gdrive-backup
The rclone remote and OAuth token (in ~/.config/rclone/rclone.conf) are
also left alone. Remove with rclone config delete <remote>.
MIT. See LICENSE.