GNU/Linux Projects

To Home Page

Srsync - a script using rsync

Last modifications: 24 December 2014

About srsync

Why srsync?

Rsync is a great and powerful tool for synchronizing directories. But you easily make mistakes when typing the (long) arguments (if you can remember them at all!). I tried some GUI's that use rsync, but I did not like the way they worked. Not being a GUI programmer, I wrote the script srsync to make using rsync easier.

What is srsync?

Srsync is a bash script. You run it from the command line.

The idea behind the script is simple: put those "difficult" rsync arguments in a configuration file (just another script, actually) and present the user with simple text menus. In the configuration file you can configure multiple sync sessions. During a sync session two directories are synchronized (this is done by rsync).

To give you an idea, the main menu looks like this:

Main Menu

See Usage for an explanation of the menus.


Install the script

Installation of srsync is done in 3 steps:

  1. Download the tar archive containing srsync
  2. Unpack the tar archive and place all files in one directory
  3. Add this directory to the path variable in your .profile
    (for example: PATH="/home/user/srsync:$PATH")

Note: Srsync will try to find the configuration file 'srsync.config' first in the PATH, than in the current working directory. So if you skip step 3, you can only start srsync from the directory where the file 'srsync.config' is stored.

Install rsync

You need to install rsync on the local computer where you run the script. Also install rsync on any remote GNU/Linux computer to synchronize to. See the rsync website for more information about rsync.


Configuration items in the configuration file 'srsync.config':

count    Number of configured sync sessions
         (only sync sessions 1 till <count> are shown in main menu)
i        Sync session number
name[i]  Name of sync session (this name is shown in main menu)
ldir[i]  Source or local directory (must end with "/")
rdir[i]  Destination or remote directory (must end with "/")
args[i]  Rsync options/arguments (see: Often used rsync options)

Note: The configuration file is a bash script. It will execute any bash script command inside it. Only use assignments to the items listed above, for example: count=5. Do not use spaces around the = sign. Use quotes around strings.


Starting srsync

Run srsync from a command prompt as follows:

$ srsync [OPTION [SESSION]]


no OPTION    show main menu
-s SESSION   show session menu
-x SESSION   execute session (synchronize directly)
-h           show help
-v           show version and copyright info

with SESSION = session number in config file

Srsync with the -x option, does not require further user action and may therefore be used for scheduling (for example with cron).

Main menu

Start srsync with no option, to get the main menu.

Main Menu

Tip: To start srsync with a mouse click, make a launcher/starter on your desktop.

From the main menu above you can choose which sync session you want to execute. If you choose a session (enter the session number), the session menu appears.

Session menu

Below the session menu for session 1: "Data Backup".

Session Menu

You can choose different actions for a session:

1Preview - only show what wil be done (dry run, no updates)
2Synchronize - execute session
-1Preview inverse - preview with source and destination reversed
-2Synchronize inverse - synchronize with source and destination reversed
iSession Info - show session info as configured in config file
qQuit - exit menu (in this example you return to the main menu)

Exit codes

Srsync exits with one of the following exit codes:

0No error or user quits from menu
1Error reading configuration file
2Wrong argument
3Error in configuration file
4Rsync error (exit code 4 can only occur with the -x option)

When the user quits from a menu, the exit code will always be 0.

Often used rsync options

Below a list of rsync option you might want to use:

-a, --archive            archive mode
                         equals -rtlpgoD (no -H,-A,-X)
-r, --recursive          recurse into directories
-t, --times              preserve modification times (only update changed files)
-l, --links              copy symlinks as symlinks
-p, --perms              preserve permissions
-g, --group              preserve group
-o, --owner              preserve owner (super-user only)
-D                       same as --devices --specials 
    --devices            preserve device files (super-user only)
    --specials           preserve special files

    --delete             delete extraneous files from dest dirs
-v, --verbose            increase verbosity (more info)
-h, --human-readable     output numbers in a human-readable format
    --modify-window=NUM  compare mod-times with reduced accuracy

Do not use the following options in the configuration file. These options are used in srsync already where appropriate.

-n, --dry-run            perform a trial run with no changes made (preview)
    --progress           show progress during transfer (synchronization)

Rsync and different file systems

Ext FS

If the destination and source directories are on ext file systems, you may use for example the following rsync options:

-a (same as: -rtlpgoD)
-a --delete
-avh --delete


On NTFS the options -l -p -g -o, -D (and therefore also -a) are not supported. If the destination or source directory is on NTFS, use -rt in stead of the option -a. For example:

-rt --delete
-rtvh --delete


USB sticks and media players often use the FAT file system. If you want to synchronize a FAT stick or player, you need to use a special rsync option.

On a FAT file system, just like NTFS, the -a option is not supported. Furthermore the time stamp on a FAT file system is inaccurate. This means that during synchronization, all files (unchanged files too) are updated, even with the -t option. To avoid this, use the special option --modify-window=1:

-rt --modify-window=1
-rt --delete --modify-window=1
-rtvh --delete --modify-window=1

Note: When syncing to my MP3 player, sometimes unchanged files are updated, even with the -t option and --modify-window=1. I discovered a time stamp mismatch (between the files on my computer and the files on my player) of exactly one hour or one hour and one second (something to do with summer and winter time?). To prevent unchanged files from being updated, I changed --modify-window=1 to --modify-window=3601.

Remote login without password

Each time you synchronize to a remote computer, you will have to enter a user name and password for that remote computer. If you do not like that, you can automatize the remote login.

Say you run srsync as user andy on computer alfa and you want to synchronize to computer beta as user bernie. You will need an automatic login from computer alfa as user andy to computer beta as user bernie.

  1. First log in on computer alfa as user andy and generate a pair of authentication keys (a public key and a private key):
    andy@alfa:~$ ssh-keygen -t rsa
    Use the default name id_rsa for the file in which to save the private key (just hit enter) and do not use a passphrase (hit enter twice).
  2. Now use ssh to create a directory /home/bernie/.ssh on computer beta as user bernie (the directory may already exist, which is fine):
    andy@alfa:~$ ssh bernie@beta mkdir .ssh
    You will have to enter bernie@beta's password.
  3. Finally append user andy's new public key to the file /home/bernie/.ssh/authorized_keys on computer beta as user bernie:
    andy@alfa:~$ cat .ssh/ | ssh bernie@beta 'cat >> .ssh/authorized_keys'
    You will have to enter bernie@beta's password again.
  4. Check if you can log into computer beta as user bernie from computer alfa as user andy without password:
    andy@alfa:~$ ssh bernie@beta

GNU General Public License

Srsync is free software. This means that everyone may use, copy and modify srsync and even distribute modified versions. Srsync is published under the GNU General Public License. This ensures that the script remains free.


I know srsync is just a simple script. So why the fuss to publish it under this "copyleft" license? For me it is just a way to show that I support free software. And I also wanted to see how difficult it would be to publish srsync under the GNU GPL. Now I know: it is easy!

More information about free software and the GNU General Public License can be found on the website of the Free Software Foundation.