Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Synchronize the MY-MUSIC folders on a local and a network mounted computer
- # Run this script with the option "test" to do a dry-run instead of actual sync
- # Define library paths
- RemoteLibrary="/Volumes/canton/Google Drive/MY-MUSIC"
- LocalLibrary="/Users/canton/Google Drive/MY-MUSIC"
- # Check if 'test' argument is passed
- if [[ "$1" == "test" ]]; then
- RSYNC_OPTIONS="--dry-run"
- echo -e "\n*** Running in --dry-run test mode. ***"
- else
- RSYNC_OPTIONS=""
- fi
- # Exit if files are not found
- if [[ ! -f "$LocalLibrary/TRAKTOR4/collection.nml" ]] || [[ ! -f "$RemoteLibrary/TRAKTOR4/collection.nml" ]]; then
- echo ""
- echo "One or both of the TRAKTOR4/collection.nml files cannot be found. Mount a volume?"
- echo "Local: $LocalLibrary"
- echo "Network: $RemoteLibrary"
- exit 1
- fi
- # Check modification times
- LocalModTime=$(stat -f "%m" "$LocalLibrary/TRAKTOR4/collection.nml" 2>/dev/null)
- RemoteModTime=$(stat -f "%m" "$RemoteLibrary/TRAKTOR4/collection.nml" 2>/dev/null)
- # Compare modification times and set sync direction
- if [[ $LocalModTime -gt $RemoteModTime ]]; then
- src="$LocalLibrary"
- dest="$RemoteLibrary"
- newerMessage="FROM THIS COMPUTER: "
- olderMessage="TO THE REMOTE COMPUTER:"
- else
- src="$RemoteLibrary"
- dest="$LocalLibrary"
- newerMessage="FROM THE REMOTE COMPUTER:"
- olderMessage="TO THIS COMPUTER: "
- fi
- # Show modification times and prompt for confirmation
- echo -e "\nHere are the modification times for the two libraries:"
- echo "THIS COMPUTER: $(date -r $LocalModTime)"
- echo "REMOTE: $(date -r $RemoteModTime)"
- echo ""
- echo -e "So, we are going to synchronize\n$newerMessage $src\n$olderMessage $dest"
- read -p "---> Type 'yes' to confirm: " confirm
- if [[ $confirm == "yes" ]]; then
- echo "*** SYNCHRONIZING... ***"
- rsync -avzh --delete $RSYNC_OPTIONS "$src/" "$dest/"
- echo "*** SYNCHRONIZING COMPLETE! ***"
- else
- echo "Synchronization canceled."
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement