Advertisement
Guest User

Synch Traktor Libraries

a guest
Dec 1st, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #!/bin/bash
  2. # Synchronize the MY-MUSIC folders on a local and a network mounted computer
  3. # Run this script with the option "test" to do a dry-run instead of actual sync
  4.  
  5. # Define library paths
  6. RemoteLibrary="/Volumes/canton/Google Drive/MY-MUSIC"
  7. LocalLibrary="/Users/canton/Google Drive/MY-MUSIC"
  8.  
  9. # Check if 'test' argument is passed
  10. if [[ "$1" == "test" ]]; then
  11. RSYNC_OPTIONS="--dry-run"
  12. echo -e "\n*** Running in --dry-run test mode. ***"
  13. else
  14. RSYNC_OPTIONS=""
  15. fi
  16.  
  17. # Exit if files are not found
  18. if [[ ! -f "$LocalLibrary/TRAKTOR4/collection.nml" ]] || [[ ! -f "$RemoteLibrary/TRAKTOR4/collection.nml" ]]; then
  19. echo ""
  20. echo "One or both of the TRAKTOR4/collection.nml files cannot be found. Mount a volume?"
  21. echo "Local: $LocalLibrary"
  22. echo "Network: $RemoteLibrary"
  23. exit 1
  24. fi
  25.  
  26. # Check modification times
  27. LocalModTime=$(stat -f "%m" "$LocalLibrary/TRAKTOR4/collection.nml" 2>/dev/null)
  28. RemoteModTime=$(stat -f "%m" "$RemoteLibrary/TRAKTOR4/collection.nml" 2>/dev/null)
  29.  
  30. # Compare modification times and set sync direction
  31. if [[ $LocalModTime -gt $RemoteModTime ]]; then
  32. src="$LocalLibrary"
  33. dest="$RemoteLibrary"
  34. newerMessage="FROM THIS COMPUTER: "
  35. olderMessage="TO THE REMOTE COMPUTER:"
  36. else
  37. src="$RemoteLibrary"
  38. dest="$LocalLibrary"
  39. newerMessage="FROM THE REMOTE COMPUTER:"
  40. olderMessage="TO THIS COMPUTER: "
  41. fi
  42.  
  43. # Show modification times and prompt for confirmation
  44. echo -e "\nHere are the modification times for the two libraries:"
  45. echo "THIS COMPUTER: $(date -r $LocalModTime)"
  46. echo "REMOTE: $(date -r $RemoteModTime)"
  47. echo ""
  48. echo -e "So, we are going to synchronize\n$newerMessage $src\n$olderMessage $dest"
  49. read -p "---> Type 'yes' to confirm: " confirm
  50.  
  51. if [[ $confirm == "yes" ]]; then
  52. echo "*** SYNCHRONIZING... ***"
  53. rsync -avzh --delete $RSYNC_OPTIONS "$src/" "$dest/"
  54. echo "*** SYNCHRONIZING COMPLETE! ***"
  55. else
  56. echo "Synchronization canceled."
  57. fi
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement