Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- TEMP_FOLDER=$$
- echo $TEMP_FOLDER
- LOCAL_FOLDER=/home/pi/tmp/Transcode/Tdarr_out
- COPY_FOLDER=/mnt/hd2_nfs/Tdarr/copying #A.K.A Buffer folder
- FINAL_FOLDER=/mnt/hd2_nfs/Tdarr
- if [ -z "$(ls -A $LOCAL_FOLDER)" ]; then
- ### Take action if no files ###
- echo "No files... Exit."
- exit 0
- fi
- echo "Files exist. Continuing..."
- if [ -d "$COPY_FOLDER" ]; then
- ### Take action if dir exists ###
- echo "Another process is already copying something... Exit."
- exit 0
- fi
- echo "Not copying anything. Continuing..."
- #Create temp folder in the buffer folder with random identifier
- mkdir -p $COPY_FOLDER/$TEMP_FOLDER/
- #Finds files already fully copied to the local Tdarr Output Folder
- #Display those files
- #Copy to the remote buffer folder
- #Remove the local files
- cd $LOCAL_FOLDER
- 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
- echo "Finished Find/Copy/Remove originals"
- #Move the files to the final folder using hard links
- sudo cp -rl --remove-destination $COPY_FOLDER/$TEMP_FOLDER/* $FINAL_FOLDER/ #hard links, copying to the output folder
- echo "Hard Links done"
- #Remove the TEMP folder inside the buffer folder
- sudo rm -R $COPY_FOLDER/$TEMP_FOLDER/ #remove temp
- #Remove the buffer folder if empty
- sudo rm -d $COPY_FOLDER
- #Clean local empty folders left
- sudo find $LOCAL_FOLDER/* -type d -empty -delete
- echo "Remove unused folder done"
- echo "Finished... Exit"
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment