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 (e.g. using local or stick as defined in the ini file) 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:
./syncdrives.sh -a -3 local
./syncdrives.sh -a -3 remote
./syncdrives.sh -d -a -3 lan local
./syncdrives.sh -D 7 -d -a -5 local stick
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] [-s] [-d] [-D daysback] [-v] [-g|-G] [-T] <-1|-2|-3|...|-9> source_drive [dest_drive]
where: source drive where the files will come from
dest_driver where the files will go to (there is a default which can be defined in the ini file)
both the above are defined in the ini file, e.g. DEST_local=mylocal, DRIVE_stick=/mnt/storengo
-a is actually do, otherwise dry run only
-c skip files based on checksum, not mod-time and size
-s request sudo rights for copy (need for some devices/lan)
-d delete files in destination which are not in source
-D daysback will ignore the rsync checking features and use files newer than the days specified
-v increase verbose levels
-g is do git garbage collection FIRST
-G is do git garbage collection ONLY
-T is to do tidy level 1, which sets .sh to executable again
-1...-9 is the dirset to copy, current is: ddrive (you MUST select one dirset to actual do anything)
e.g. To only copy from c to e: syncdrives.sh -a -1 local
Copy different directories: syncdrives.sh -a -3 local stick
set execute rights of scripts: chmod ug+x *.sh
./syncdrives.sh -a -5 lan local
./syncdrives.sh -a -T -5 local stick
./syncdrives.sh -a -T -3 local
./syncdrives2.sh -a -1 -s local lan
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 {} \;
To track progress of the rsync, if it is taking a long time try the following:
sudo strace -e open,openat $(ps -o lwp= -LC rsync | sed 's/^/-p/')
)
)