nobodyflows

psp-rsync-save-script.sh

Jan 25th, 2025 (edited)
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.67 KB | Gaming | 0 0
  1. #!/bin/bash
  2.  
  3. # Define the source and remote paths
  4. SOURCE="/local/path/to/PSP/SAVEDATA/"
  5. REMOTE_HOST="SSH-HostName"
  6. REMOTE_PATH="/remote/path/to/RetroArch/psp/"
  7. LOCAL_MOUNT_POINT="/local/sshfs/path/for/temp/use"
  8.  
  9. # Prompt the user to select sync direction
  10. echo "Select sync direction:"
  11. echo "1. Mirror PSP to Raspberry Pi"
  12. echo "2. Mirror Raspberry Pi to PSP"
  13. read -p "Enter your choice (1 or 2): " choice
  14.  
  15. # Validate the choice
  16. if [[ "$choice" != "1" && "$choice" != "2" ]]; then
  17.     echo "Invalid choice. Exiting..."
  18.     exit 1
  19. fi
  20.  
  21. # Mount the remote directory using sshfs
  22. echo "Mounting remote directory $REMOTE_HOST:$REMOTE_PATH to $LOCAL_MOUNT_POINT..."
  23. sshfs $REMOTE_HOST:$REMOTE_PATH $LOCAL_MOUNT_POINT
  24.  
  25. if [ $? -ne 0 ]; then
  26.     echo "Failed to mount remote directory. Exiting..."
  27.     exit 1
  28. fi
  29.  
  30. # Function to mirror contents with exclusions
  31. mirror_contents() {
  32.     local src="$1"
  33.     local dest="$2"
  34.     echo "Mirroring contents of $src to $dest..."
  35.     rsync -av --delete --inplace --no-perms --exclude=".stfolder" --exclude=".syncthing.*" "$src" "$dest"
  36. }
  37.  
  38. # Perform mirroring based on user choice
  39. if [ "$choice" == "1" ]; then
  40.     echo "You chose to mirror PSP to Raspberry Pi."
  41.     mirror_contents "$SOURCE" "$LOCAL_MOUNT_POINT"
  42. elif [ "$choice" == "2" ]; then
  43.     echo "You chose to mirror Raspberry Pi to PSP."
  44.     mirror_contents "$LOCAL_MOUNT_POINT" "$SOURCE"
  45. fi
  46.  
  47. # Unmount the remote directory after mirroring is completed
  48. echo "Unmounting remote directory..."
  49. fusermount -u $LOCAL_MOUNT_POINT
  50.  
  51. if [ $? -eq 0 ]; then
  52.     echo "Remote directory unmounted successfully."
  53. else
  54.     echo "Failed to unmount remote directory."
  55.     exit 1
  56. fi
  57.  
Advertisement
Add Comment
Please, Sign In to add comment