linuxserver / docker-transmission

GNU General Public License v3.0
582 stars 180 forks source link

Find orphan torrent files script addition #196

Closed sotiris-bos closed 1 year ago

sotiris-bos commented 2 years ago

linuxserver.io


Desired Behavior

Hello, I have manually added this to my transmission container, I think the userbase could benefit from it.

There is a script provided by: https://gist.github.com/alexnorton/1a6bfcf3528bd18f8dfb

This helps to identify which files and folders in the downloads directory are not a member of a torrent currently loaded by transmission. This script identifies files that are taking space in the downloads directory, files that were left there as a result of deleting a torrent but retaining the data.

The script needs modification. First of all, gawk needs to be installed because awk gives Regex error "Repetition not preceded by valid expression"

The modified script is this:

#!/bin/bash

DIRECTORIES="/downloads_dir_1 /downloads_dir_2 ... /downloads_dir_n"

grep -Fxv -f \
  <( \
    transmission-remote -l | gawk 'NR!=1 {sub(/*/, "", $1); print $1}' | sed \$d | while read id; do
      transmission-remote -t $id -i | sed -n -E -e "s/(Name|Location): (.+)/\2/p" | sed -E "N;s/  (.+)\n  (.+)/\2\/\1/"
    done
  ) \
  <(find $DIRECTORIES -mindepth 1 -maxdepth 1)

After the script is added, the DIRECTORIES variable must be set. This could probably be automated or set by environment variables.

At last, running docker exec transmission ./transmission_orphaned.script reveals the orphaned downloads.

This script only works when ran inside the container, because the directories are different between the container and the host. That is why I feel like it would be a nice addition to this image.

github-actions[bot] commented 2 years ago

Thanks for opening your first issue here! Be sure to follow the bug or feature issue templates!

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

spider1163 commented 1 year ago

Thanks for the idea, I will try the script

spider1163 commented 1 year ago

This script worked better for me :

#!/bin/bash

# get a list of all torrents transmission-remote 2.52
transmission-remote --auth user:pass -t all --files > _all_torrents.tmp

# all items in this directory
for i in *
do
        # is it a file or a directory
        if test -f "$i" -o -d "$i"
        then
                # does it NOT exist in the list of all torrent files
                #if [[ $all_files != *"$i"* ]]
                if ! grep -Fq "$i" _all_torrents.tmp
                then
                        # does it not start with an underscore (my special char for files in directory not related to transmission
                        if [[ "$i" != _* ]]
                        then
                                # delete them
                                echo rm -rf \"$i\"
                                # rm -rf "$i"
                        fi
                fi
        fi
done

# clear tmp file
rm _all_torrents.tmp

source : https://unix.stackexchange.com/a/371869

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

drizuid commented 1 year ago

this would be fine as a docker mod but it isn't something we would put directly into the container. https://www.linuxserver.io/blog/2019-09-14-customizing-our-containers

feel free to create a mod and PR it to us

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. This might be due to missing feedback from OP. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 1 year ago

This issue is locked due to inactivity