One command copy/sync between local and remote directories using rclone. Made for simplicity and efficiency by excluding unnecessary files.
Version: 4.1 (2026-03-19) Repository: https://github.com/IBL-bioinfo/sync-with-rclone
- Copy
sync-with-rclone.shandsync-with-rclone.configto your target folder - Edit
sync-with-rclone.configto set your remote location and preferences chmod u+x sync-with-rclone.sh- Run:
./sync-with-rclone.sh pullor./sync-with-rclone.sh push
./sync-with-rclone.sh pull|push [options] [additional rclone parameters]
-h, --help— Show help message and exit--sync— Use rclone sync instead of default copy operation (WARNING: deletes files in destination not present in source)--exclude "[pattern]"— Exclude files matching pattern (can be used multiple times)--include "[pattern]"— Include files matching pattern (can be used multiple times), will automatically exclude all other files-y— Use with caution: skip confirmation prompts and run non-interactively
# Simple pull
./sync-with-rclone.sh pull
# Push with dry-run preview
./sync-with-rclone.sh push --dry-run
# Sync with automatic confirmation
./sync-with-rclone.sh push --sync -y
# Push only source files
./sync-with-rclone.sh push --include "src/**" --dry-run
# Push with custom rclone timeout
./sync-with-rclone.sh push --timeout 120mAll settings are stored in sync-with-rclone.config:
REMOTE_NAME— Name of your rclone remote, you must have this remote configured in rclone by runningrclone configand following the prompts (you probably named your config e.g.rdfor Research Drive)REMOTE_PATH— Path on the remote (e.g.,/path/to/backup)ALLOW_PULL— Set tofalseto disable pull operations, useful for write-only backup scriptsALLOW_PUSH— Set tofalseto disable push operations, useful for read-only restore scriptsRECORD_GIT_COMMIT— Set totrueto record git commit info when pushingexclude— Array of additional patterns to exclude from configglobal_exclude— Array of patterns to always exclude, do not change unless you know what you're doing (includes common "no need to backup" files like*.tmp, etc.)
- Built-in ignore list — Automatically excludes common "no need to backup" files
- Git support — Records commit hash and status for git repositories (without syncing
.gitdirectories) - Flexible filtering — Include/exclude patterns support via command-line or config
- Sync with safety — Sync operation shows preview of deletions and asks for confirmation
- Non-interactive mode — Use
-yflag to skip prompts or--dry-runfor preview without changes
Git itself is a version control system. The small files git generated in the .git directory are not necessary to backup, and can be easily regenerated by cloning the repository again. Most importantly, as creating files are time consuming on the remote, the small files in .git directory will greatly slow down the rclone progress, especially for large repositories. This is why the script excludes the .git directory by default. However, it can be useful to keep track of the git commit hash and status at the time of backup for reference.
⚠️ WARNING: Local git repositories (without a remote) will lose their version tracking after pushing to remote. Only the latest commit hash and status will be recorded in the text file. If you want to keep the full git history, configure a remote (GitHub, GitLab, etc.) and push to it. That remote is your actual version tracking—the backup script only records the current state for reference.
Thus, this script does not sync the .git directory at all, but when RECORD_GIT_COMMIT=true (default) and pushing, it records the current git commit hash, remote URLs, and status in a [REPOSITORY_DIR]_git_repository.txt file in the same directory as the repository. This allows you to keep track of the repository's state at the time of backup. This includes:
- The current commit information of the repository (commit hash, date, author, message)
- The remote URLs configured for the repository
- The current status of the repository (modified, added, deleted, untracked files)
Example content of the generated git repository information file:
============ git repository information ============
Date: Sun Jul 19 12:16:26 CEST 2025
Commit Hash: 3688o888id6fb...
Remote(s):
origin: [email protected]:user/repo.git
backup: [email protected]:group/repo.git
Git Status:
Working directory clean
============ git repository information ============
Date: Sun Jul 20 14:09:18 CEST 2025
Commit Hash: 5uuuuuuuuuuuu...
Remote(s):
origin: [email protected]:user/repo.git
backup: [email protected]:group/repo.git
Git Status:
M file-modified.txt
A file-added.txt
?? file-untracked.txt
D file-deleted.txt
Version 4.1 (2026-03-19): Cleaner Dry-Run No-Change Output
This release improves clarity when a dry-run finds no file-level changes:
-
CLEAR NO-CHANGE MESSAGE
- Added explicit output: "Nothing will change." when dry-run has no pending changes
- Avoids confusion caused by only seeing rclone summary/check counters
-
EARLY EXIT WHEN NO CHANGES
- Real operation now stops before confirmation/execution if dry-run pre-check reports no changes
- Prevents unnecessary prompts and no-op runs
Version 4.0 (2026-03-10): Improved Safety for Sync Operations
This release prioritizes safety and usability when performing sync operations to prevent accidental data loss:
-
SAFER DEFAULT BEHAVIOR
- Default operation is now "copy" (safer) instead of fixing it in the config file
- The OPERATION variable is no longer set in the config file
-
COMMAND-LINE SYNC FLAG
- Added --sync flag to switch to sync operation at runtime
- Clear warnings in help output about destructive behavior
- Allows users to override the safe default (copy) only when intentional
-
DELETION PREVIEW AND CONFIRMATION
- For sync operations, script performs dry-run first
- Shows user which files will be permanently deleted
- Requires explicit confirmation before proceeding
- Non-interactive mode (-y) waits 5 seconds before auto-confirming
-
IMPROVED DOCUMENTATION
- Updated version numbers in script and help output
- Clarified usage patterns and behavior in help text
- Better explanations of safe vs dangerous operations