Originally developed out of a need to copy between Windows (under Mobaxterm) and Linux (native) machines for cross development, this script was written as a wrapper around rsync to allow easy working on multiple machines by copying over specific directories between the machines by using a USB drive, which thus also acts as a backup device.

The devices and directories are specified in the syncdrives.ini file.

In command line you specify the MASTER (using local or remote) device and it works out what your source and targets are based on the machine you are on, this allows different machine definitions for devices to be handled without issues.

As rsync is used, the comparison of whether a file has changed and thus needs copying is the same logic, files are checked by size and timestamp (default mode), or by content/checksum (-c).

Examples:

As you can see from some the last few parameters, I have added some additional stuff to aid/tidy inter-machine development, you can ignore those flags/features.

Usage:
./syncdrives.sh -h
Setting features for Linux
usage: ./syncdrives.sh [-a] [-c] [-g|-G] [-D daysback] [-d] [-v] [-T] [-1|-2|-3|-4|-5] source_drive [dest_drive]
where: source drive = local|remote|storengo|lmachine|rmachine
       local will use the local machine as the master and PUSH changes to the stick
       remote will use the stick as the master and PULL changes to the local machine
       lmachine will use the local machine, main drive as master and PUSH to the secondary
           drive on the local machine
       rmachine will use the local machine, secondary drive as master and PUSH to the main
           drive on the local machine
-a is actually do, otherwise dry run only
-v increase verbose levels
-D daysback will ignore the rsync checking features and use files newer than the days specified
-d delete files in destination which are not in source
-1 is to copy: only the ddrive directory, current is: ddrive
-2 is to copy: ddrive and home directories, current is: ddrive
-3 is to copy: ddrive, home and work directories (but NOT workspace), current is: ddrive
-4 is to copy: ddrive, home and work directories, current is: ddrive
-5 is to copy: only the var directory, current is: ddrive
-g is do git garbage collection FIRST
-G is do git garbage collection ONLY
-c is to skip based on checksum, not mod-time and size 
-T is to do tidy level 1, which sets .sh to executable again
e.g. to only copy from c to e: ./syncdrives.sh -a c 
 
To copy 2 sets of drives and reset the shell scripts do:
./syncdrives.sh -a -3 remote
chmod ug+x *.sh
./syncdrives.sh -a -5 remote
./syncdrives.sh -a -T -5 local
./syncdrives.sh -a -T -3 local
 
NOTE: If there is an error on Linux with remote being read-only do the following:
  sudo dosfsck -a /dev/sdb1

To make one of the drives a master, do something like:
  find /drives/c/ddrive/ -exec touch {} \;

Configuration

This was written when .ini files were the thing, thus the configuration is an ini file with two main types of entry, a machine description and a directory set description.
  1. The machine description allows a specific machine to be identified and the relevant disks which will be processed to be defined.
  2. The directory set allows a set of directories which will be processed to be defined.

Back