Hiya huzzak,
I was inspired by your scripts and the things you were asking about to fix up my own sync problems. I took your script and adjusted it a little to suit my needs better, but thought perhaps you might find it helpful as well.
The primary change is that rsync does an initial dry run, and then lists which files it intends to update. The user can then either click "Ok" to accept the list and run, or can hit cancel to abort the sync. I have a slight data paranoia atm... if this works well enough I will likely eventually make it quiet.
For me, the udev rules needed to be updated so they only respond to the *final* mounting event, i.e., when the volume itself is actually mounted. I also added a nohup to the command so the volume would mount while the script was processing, else the script kinda prevents anything else from happening.
The new udev rules:
Code:
KERNEL=="sdc[0-9]*", SUBSYSTEM=="block", BUS=="usb", SYSFS{serial}=="1aa4f7807494c2", SYMLINK=="jet_drive", RUN+="/usr/bin/nohup /usr/local/bin/sync-thumb.sh"
The modified sync-thumb.sh script:
Code:
#!/bin/bash
#
# CONFIG SECTION
# Local folder to sync with
SYNC_LOC=/media/haven_drive1/documents/philip/USB
DEV_LOC=/media/disk
# r - recursive
# l copy symlinks as symlinks
# p permissions
# t preserve times
# g preserve group
# o preserver owner
# D --devices --specials
DRY_SYNC_OPTIONS="-rltxuin"
SYNC_OPTIONS="-rltxu"
# SCRIPT SECTION
# Wait for thumbdrive to settle
sleep 3
# Synchronize thumbdrive with local
FROM_LOCAL=`rsync ${DRY_SYNC_OPTIONS} ${DEV_LOC}/ ${SYNC_LOC}/`
# Synchronize local with thumbdrive
FROM_USB=`rsync ${DRY_SYNC_OPTIONS} ${SYNC_LOC}/ ${DEV_LOC}/`
# Combine the outputs from the two rsync functions.
# The grep command ignores any line beginning with a '.'. These files are not being updated in any way
COMPLETE_LIST=`(echo -e "===From Local:===\n${FROM_LOCAL}" && echo -e "==============\n" && echo -e "===From USB:===\n${FROM_USB}") | grep ^[^\.]`
# Get the username of whoever is at the local X11 display.
# If we don't find one, then exit.
X11User=`who | grep :0\ | cut -f 1 -d ' '`
if [ -z "$X11User" ] ; then
exit
fi
export DISPLAY=":0.0"
export HOME="/home/$X11User"
# Don't bother informing the user if no files have changed
if [[ ("${FROM_LOCAL}" == ".d..t...... ./") && ("${FROM_USB}" == ".d..t...... ./") ]]; then
exit
fi
# Inform user that synchronization is complete and display the modified files
echo "${COMPLETE_LIST}" | sudo -u $X11User zenity --list --title "Files to transfer" --text "File transfer summary" --column "Files" --height 800 --width 600 --display=:0 && RESPONSE=ok
if [ "${RESPONSE}" == "ok" ];
then
# Synchronize thumbdrive with local
FROM_USB=`rsync ${SYNC_OPTIONS} ${DEV_LOC}/ ${SYNC_LOC}/`
# Synchronize local with thumbdrive
FROM_LOCAL=`rsync ${SYNC_OPTIONS} ${SYNC_LOC}/ ${DEV_LOC}/`
fi
Bookmarks