wsegatto

ARM Tdarr Move to Network Drive

Aug 5th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.53 KB | None | 0 0
  1. #!/bin/bash
  2. TEMP_FOLDER=$$
  3. echo $TEMP_FOLDER
  4.  
  5. LOCAL_FOLDER=/home/pi/tmp/Transcode/Tdarr_out
  6. COPY_FOLDER=/mnt/hd2_nfs/Tdarr/copying #A.K.A Buffer folder
  7. FINAL_FOLDER=/mnt/hd2_nfs/Tdarr
  8.  
  9. if [ -z "$(ls -A $LOCAL_FOLDER)" ]; then
  10.   ### Take action if no files ###
  11.   echo "No files... Exit."
  12.   exit 0
  13. fi
  14.  
  15. echo "Files exist. Continuing..."
  16.  
  17. if [ -d "$COPY_FOLDER" ]; then
  18.   ### Take action if dir exists ###
  19.   echo "Another process is already copying something... Exit."
  20.   exit 0
  21. fi
  22. echo "Not copying anything. Continuing..."
  23.  
  24. #Create temp folder in the buffer folder with random identifier
  25. mkdir -p $COPY_FOLDER/$TEMP_FOLDER/
  26.  
  27. #Finds files already fully copied to the local Tdarr Output Folder
  28. #Display those files
  29. #Copy to the remote buffer folder
  30. #Remove the local files
  31. cd $LOCAL_FOLDER
  32. find . -type f \( -iname "*" ! -iname "*TdarrCache*" \) -exec echo "{}" \; -exec cp -R --parents {} $COPY_FOLDER/$TEMP_FOLDER/ \;  -exec sudo rm {} + #get files, copy and delete source
  33. echo "Finished Find/Copy/Remove originals"
  34.  
  35. #Move the files to the final folder using hard links
  36. sudo cp -rl --remove-destination $COPY_FOLDER/$TEMP_FOLDER/* $FINAL_FOLDER/ #hard links, copying to the output folder
  37. echo "Hard Links done"
  38.  
  39. #Remove the TEMP folder inside the buffer folder
  40. sudo rm -R $COPY_FOLDER/$TEMP_FOLDER/ #remove temp
  41. #Remove the buffer folder if empty
  42. sudo rm -d $COPY_FOLDER
  43. #Clean local empty folders left
  44. sudo find $LOCAL_FOLDER/* -type d -empty -delete
  45. echo "Remove unused folder done"
  46.  
  47. echo "Finished... Exit"
  48. exit 0
  49.  
Advertisement
Add Comment
Please, Sign In to add comment