Skip to content

mrAibo/rcopy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rcopy - Remote Copy Tool

rcopy is a versatile and powerful Bash function designed for efficient and customizable copying of files and directories, both locally and between remote systems. Leveraging the capabilities of rsync, scp, and additional features like compression, file exclusion, and bandwidth control, rcopy aims to simplify and enhance the process of data transfer.

Installation

Due to its comprehensive functionality, rcopy is best sourced from outside your .bashrc file to keep your shell configuration clean and fast. You can source the script whenever needed or in specific scripts that require its functionality.

  1. Clone the repository or download the rcopy.sh script to your preferred location.
git clone https://github.com/mrAibo/rcopy.git
  1. Use it either way — no build step:
source /path/to/rcopy.sh      # defines the rcopy function for this shell
# or run it directly, no sourcing required:
/path/to/rcopy.sh src dest

Features

  • Dual Protocol Support: Choose between rsync (default) or scp
  • Compression: Optional GZIP compression for slow networks
  • Sync Mode: Server-to-server synchronization with date filtering
  • Bandwidth Control: Limit transfer speed (rsync only)
  • Exclusion Patterns: Support for both inline patterns and exclude files
  • SSH Integration: Custom ports, keys, and SSH config compatibility
  • Autocomplete: Intelligent path completion for local/remote files
  • Verbose Mode: Detailed transfer progress visualization

Usage

rcopy [OPTIONS] source destination

Options

  • -h, --help: Show help message.
  • -z, --compress: Compress data during transfer.
  • -m, --move: Move files instead of copying (delete source after transfer).
  • -u, --user: Specify remote username.
  • -p, --port: Specify SSH port number.
  • -i, --identity: Specify SSH identity file (private key).
  • -l, --limit: Limit bandwidth (KB/s, rsync only).
  • -e, --exclude: Exclude files matching pattern or use exclude file.
  • -s, --use-scp: Force using SCP instead of rsync.
  • -v, --verbose: Show detailed progress information.
  • -S, --sync: Enable sync mode between remote servers.
  • --source-host: Source server hostname/IP.
  • --target-host: Target server hostname/IP.
  • --days: Sync files modified in last DAYS days.

Examples

Basic Examples

  • Copy a local directory:
rcopy ~/documents/project /backup/
  • Copy to a remote server:
rcopy ~/documents user@server:/backup/
  • Copy from a remote server:
rcopy user@server:/remote/data ~/local/

Advanced Examples

  • Compress and move with verbose output:
rcopy -z -m -v ~/large-project server:/backup/
  • Exclude log files and use custom SSH port:
rcopy -e "*.log" -p 2222 ~/project user@server:/backup/
  • Enable direct server-to-server transfers with -S/--sync:
rcopy -S --source-host HOST1 --target-host HOST2 /src /dest

Sync Options:

--days N: Only sync files modified in last N days

Combine with -m to move files after sync

SSH key automation

You rarely need -u/-i. rcopy delegates all key handling to SSH, so set it up once in ~/.ssh/config and drop the flags:

Host myserver
    HostName 192.0.2.10
    User bob
    IdentityFile ~/.ssh/bob_key
    IdentitiesOnly yes

Then rcopy myserver:/data /backup/ just works — user and key are picked up automatically. For passwordless operation, load the key once with ssh-add ~/.ssh/bob_key (ssh-agent) instead of passing -i every run.

Performance Tips

  • Use compression (-z) for: Text files and small documents, High-latency connections, Transfers with many small files
  • Prefer rsync for: Large directories, Partial transfers, Network-efficient updates
  • Use SCP (-s) for: Single large files, Simple transfers without advanced features

Testing

A minimal regression suite lives in test_rcopy.sh (no external deps — plain bash). It covers the fixes below and guards against regressions:

bash test_rcopy.sh

Recent fixes (v1.1)

  • -u/--user is now applied to remote source/destination specs (previously parsed but ignored — rcopy -u bob host:/x /y ran as the current user).
  • -m/--move no longer deletes a remote source. Move-mode cleanup now runs only for local sources; a remote→local move previously deleted the file on the server (silent data loss).
  • -r/--resume is corrected. Uses --partial only; the old --append-verify could corrupt a full copy when sizes already matched.
  • NO_COLOR works. Color variables are no longer readonly, so the no-color branch can actually clear them.
  • -L/--log no longer swallows errors. Logging redirection starts only after argument validation, so "Missing source or destination" stays on the terminal.
  • Dry-run preview is accurate. SSH port/identity are combined into a single -e 'ssh -p … -i …' instead of two conflicting -e flags.
  • trap EXIT cleanup no longer emits unbound variable noise under set -u.

License

rcopy is licensed under the GNU General Public License v3.0.

Contributing

Contributions are welcome! If you find any bugs, have feature requests, or would like to contribute, please open an issue or submit a pull request.

Acknowledgements

rcopy utilizes the power of existing tools like rsync, scp, ssh, tar, and gzip to deliver a seamless data transfer experience.


Note: The detailed explanation and usage examples are provided within the rcopy.sh script. Refer to the script for in-depth documentation and advanced usage scenarios.


Happy copying! 🚀

About

A powerful Bash function for efficient file transfers with advanced features like compression, bandwidth control, and sync mode.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages