Skip to content

WekaJosh/gdrive-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

gdrive-backup

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.

Requirements

If rclone is missing, both the setup wrapper and the generated runner will print a clear error with install instructions and exit non-zero.

Install

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.

Usage

./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).

Files created

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.

What the runner does

  • Sources the saved config
  • Rotates the log if it's over 10 MiB
  • Acquires a flock so concurrent runs no-op
  • Calls rclone sync with 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

Things to know

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.

Uninstall

./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>.

License

MIT. See LICENSE.

About

A Linux desktop based backup utility for google drive

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages