Sonarr Cleanup - unraid specific [SOLVED]


Recommended Posts

Hi all. After countless times of checking settings (tried turning hardlinks off and turning them on, makes no difference) and many a google, for whatever reason my sonarr docker doesn't clean up downloads after importing. My radarr docker does just fine. This applies to both torrents and usenet functions. Wondering if i'm the only one experiencing this, but if not... How do you guys clean these folders up aside from manually going in and clearing downloads every week or two? anybody have a script for something like that?

Edited by Cpt. Chaz
Link to comment
  • 3 months later...

Realize this is an old post of mine, but the problem persisted for me and i finally solved it. Below is the script I use to clean out my usenet completed downloads folder. It's set to clean out files older than 3 days, run daily. Maybe it can be useful for somebody

 

#!/bin/bash
echo "Searching for (and deleting) Files older than 3 Days"

echo "Should Only Take a Second"

#dir = WHATEVER FOLDER PATH YOU WANT CLEANED OUT
dir=/path/to/folder/

#ENTER NUMERIC VALUE OF DAYS AFTER "-MTIME +"
find $dir* -mtime +3 -exec rm -rfv {} \;

echo "Done for Now"

echo "See Ya Tomorrow"

 

Edited by Cpt. Chaz
syntax typo
  • Thanks 1
  • Upvote 1
Link to comment
  • 1 year later...

Hiya, 

 

I don't know linux well, but trying to use the above script kindly shared - I can't get it to work. Does this look right (to delete everything more than a day old):

 

#!/bin/bash
echo "Searching for (and deleting) Files older than 3 Days"

echo "Should Only Take a Second"

#dir = WHATEVER FOLDER PATH YOU WANT CLEANED OUT
dir=/mnt/user/downloads/incomplete

#ENTER NUMERIC VALUE OF DAYS AFTER "-MTIME +"
find $dir* -mtime +1 -exec rm -rfv {} \;

echo "Done for Now"

echo "See Ya Tomorrow"

 

...is my formatting of the directory ok?

Link to comment

Either the dir= line should end in a /  - look like this dir=/mnt/user/downloads/incomplete/   , OR the find command should include the slash:  $dir/* and look like - find $dir/* -mtime +1 -exec rm -rfv {} \;

Currently find is looking for files that start with incomplete in the downloads directory - in reality this: /mnt/user/downloads/incomplete* , notice the incomplete*. You have the two choices I mentioned to fix, do not use both.

give either of those a try, that should make it work.

Link to comment

Ah, fab - thank you. I've updated the location as you describe and also changed the time to zero as follows:

 

#dir = WHATEVER FOLDER PATH YOU WANT CLEANED OUT
dir=/mnt/user/downloads/incomplete/

#ENTER NUMERIC VALUE OF DAYS AFTER "-MTIME +"
find $dir* -mtime +0 -exec rm -rfv {} \;

 

However, it's still not deleting a test file I put there yesterday - any ideas?

 

Thanks! :)

Link to comment

+1, 1, and -1 also +0, 0, -0 all mean different things for mtime. But +0 will not make the mtime statement true, and will not return any files to the -exec command. Try below to see what I mean.

use this and test what changing the -mtime to those six values above. Then when this -exec ls -ltr {} \; brings back what you need then use that for the -mtime value. Test to be sure that it is doing *exactly* what you want before updating the script and and running for rm.


find  /mnt/user/downloads/incomplete/* -mtime <your test # here> -exec ls -ltr {} \;

 

*** Use at your own risk, not responsible for you using an incorrect -mtime value and removing more files than you intend. Be sure the ls -ltr {} \; is doing what you expect. ***

Link to comment
  • 2 months later...

First time poster here. I just started using unRAID and so far absolutely love it. I'm coming from Synology, which is a great platform, but I love the ability to use my own hardware and the versatility of unRAID.

 

@Cpt. Chaz, this is a great script and just what I was looking for, so thank you.

 

I am relatively new to scripting, so I was hoping you or someone else could help with a modification to this script. How hard would it be to exclude specific files and folders? I have a hidden file and folder (i.e. .file and .folder) that I need to NOT delete.

 

Could someone point me in the right direction?

 

Thanks so much for your help!

 

Edited by DepthVader
Spelling
Link to comment

Hi @DepthVader, sorry it took so long to get back to you. Not sure if you were able to solve this or not, but I admittedly had to do a little googling to find the answer. 
 

this forum here seems to show in good detail what you need. In case the link is broken in the future for anyone else coming across this post, here’s a snippet of the relevant text:

 

To exclude files and folders starting with “.” or “@“

 

find /path/to/start/search/ -not -path '*/[@.]*' -type f -mtime -2


So in your case, (since you don’t need to exclude the “@“) I think it would be something like:

find $dir* -not -path ‘*/[.]*’ -mtime +3 -exec rm -rfv {} \;


I have not personally tested this, so I don’t know for sure. Give this a try, make backups or use some test files/folders to be sure beforehand, and double check me. But I think this is it! Let me know how it goes. 

 

  • Thanks 1
Link to comment

@Cpt. Chaz

 

Thank you for your research, I really appreciate it!  I have not had a chance to play with the script yet. Life got in the way...as it does...

 

My work is crazy right now, so I'm not sure when I'll get a chance to try this out (maybe this weekend). Once I get a chance to try it out, I'll post back my findings when I'm done for others.

 

If I end up tweaking your argument, I'll post what I did.

 

I'll also read the forum you linked to, to help educate myself. 

 

Thanks again for looking into this for me!

 

😁

  • Upvote 1
Link to comment
On 3/16/2022 at 6:34 PM, Cpt. Chaz said:

 

find $dir* -not -path ‘*/[.]*’ -mtime +3 -exec rm -rfv {} \;


 

 

@Cpt. Chaz,

 

Sorry for the delayed response. I changed the -mtime to +1, thinking it would delete files over a day old....oops...it took two days (I understand why now, just didn't at the time), which delayed my response by a day. 🙃

 

Anyways....your above command worked perfectly!  It deleted all the files and folders, except the hidden ones!  

 

You are the best and thanks for all your help!

 

😁😁

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.