For a while now I’ve been using rsync to manage my file transfers and backups. I find it to be quite a powerful and flexible tool but sometimes it’s just a bit too awkward to use in a terminal.
I created this script to simplify the use of rsync to be a similar experience to using interactive cp (cp -i) but with a preview generated by rsync --archive --partial --progress --verbose --human-readable --dry-run. This gives me a chance to properly review any file changes before I decide to commit any changes.
For example, if I want sync the contents of ~/directory_a to ~/directory_b, I can do the following:
$ srsync ./directory_a/ ./directory_b/
Rsync File Transfer: DRY RUN
Source: ./directory_a/
Destination: ./directory_b/
sending incremental file list
./
file_1
sent 86 bytes received 22 bytes 216.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)
Continue? [Yes/No]: y
Continuing...
Rsync File Transfer: TRANSFER
Source: ./directory_a/
Destination: ./directory_b/
sending incremental file list
./
file_1
0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2)
sent 122 bytes received 38 bytes 320.00 bytes/sec
total size is 0 speedup is 0.00
I added a couple of other options to make syncing a bit easier. ./srsync --delete adds the option to delete files at the destination path and ./srsync --reverse reverses the paths without manually changing the paths in the command line. Continuing from the previous snippet:
$ rm ./directory_b/file_1
$ touch ./directory_b/file_0
$ srsync --delete --reverse ./directory_a/ ./directory_b/
Rsync File Transfer: DRY RUN, REVERSE, DELETE
Source: ./directory_b/
Destination: ./directory_a/
sending incremental file list
deleting file_1
./
file_0
sent 85 bytes received 35 bytes 240.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)
Continue? [Yes/No]: y
Continuing...
Rsync File Transfer: TRANSFER, REVERSE, DELETE
Source: ./directory_b/
Destination: ./directory_a/
sending incremental file list
deleting file_1
./
file_0
0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2)
sent 125 bytes received 55 bytes 360.00 bytes/sec
total size is 0 speedup is 0.00
For ease of use in scripts, I’ve also added options to replace the default rsync options, add to the current default options or include an SSH command for network transfers.
Here is an example script that I used for testing but also for making quick backups of a directory I’m currently working in:
#!/bin/sh
srsync \
${@} \
--addon='
--exclude=.backup/
' \
'./' \
'./.backup/'
And one more example script which I use to sync a remote directory to my Android phone that uses Termux:
#!/bin/sh
srsync \
${@} \
--rsh='ssh -p 8022 -i ${HOME}/.ssh/id_ed25519' \
--options='
--partial --progress --verbose --human-readable
--archive --chown=1000:1000
--mkpath
--compress
' \
'[email protected]:/storage/emulated/0/sync/' \
'/media/archive/phone/sync/'
I can easily pass the --reverse or --delete option flags to these scripts and sync in either direction with ease.
I also wrote this script to be as POSIX portable as possible. It’s only dependency is rsync and whatever dependencies rsync requires. Hopefully this means it works on any POSIX compliant shell but I’ve only tested it with busybux-ash, dash and bash so I can’t make any guarantees about other shells.
This current script has been an ongoing evolution of previous scripts I’ve made around the use of rsync, but I think this current version is everything I wanted back nearly 2 years ago when I first started working with linux and rsync.
I use it quite a lot and maybe it can be of use to someone else. If anyone has the time to review the code and offer any feedback, that would be appreciated. I am always interested in learning new POSIX scripting tricks and am open to any feedback.

