Empty .recycle after X amount of time

Status
Not open for further replies.

Wolfeman0101

Patron
Joined
Jun 14, 2012
Messages
428
I know there was a script but I can't find it or find the instructions but I want to use the recycle feature and set the files and folders in .recycle to delete permanently after 7 days. I'm using 9.1.1.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,525
I know.. I think I created the thread. But it won't open now since we've upgraded the forum software (thank you ix!). Anyway, here's my code. Use at your own risk or reward:

#!/bin/sh
find /mnt/ -name ".recycle" > /tmp/list
cat /tmp/list | xargs -I % find %/ -atime +3 -exec rm -rf '{}' \;

That finds every folder named .recycle in your /mnt (basically all zpools and UFS mounted locations). It then searches for anything more than 3 days old and deletes it forever.
 

Wolfeman0101

Patron
Joined
Jun 14, 2012
Messages
428
I know.. I think I created the thread. But it won't open now since we've upgraded the forum software (thank you ix!). Anyway, here's my code. Use at your own risk or reward:

#!/bin/sh
find /mnt/ -name ".recycle" > /tmp/list
cat /tmp/list | xargs -I % find %/ -atime +3 -exec rm -rf '{}' \;

That finds every folder named .recycle in your /mnt (basically all zpools and UFS mounted locations). It then searches for anything more than 3 days old and deletes it forever.

Cool, thanks! So do you set a cron job to run it once a day? Isn't there some trick you need to do so the .sh files don't disappear?
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,525
I put the .sh file on my pool and did a cronjob at 2am every morning. In fact, I keep all my cronjob scripts on my pool. Then I don't have to worry about updating FreeNAS and losing them.
 

Dusan

Guru
Joined
Jan 29, 2013
Messages
1,165
#!/bin/sh
find /mnt/ -name ".recycle" > /tmp/list
cat /tmp/list | xargs -I % find %/ -atime +3 -exec rm -rf '{}' \;
If I may suggest a simpler version:
[PANEL]find /mnt -path \*/.recycle/\* -atime +7 -delete[/PANEL]This should accomplish the same just without having to use the temporary file and xargs. You can schedule it as a cron command without having to create a script. Also, make sure that you do not disable atime in your ZFS Options.
 

Wolfeman0101

Patron
Joined
Jun 14, 2012
Messages
428
If I may suggest a simpler version:
[PANEL]find /mnt -path \*/.recycle/\* -atime +7 -delete[/PANEL]This should accomplish the same just without having to use the temporary file and xargs. You can schedule it as a cron command without having to create a script. Also, make sure that you do not disable atime in your ZFS Options.

Thanks!
 

Wolfeman0101

Patron
Joined
Jun 14, 2012
Messages
428
If I may suggest a simpler version:
[PANEL]find /mnt -path \*/.recycle/\* -atime +7 -delete[/PANEL]This should accomplish the same just without having to use the temporary file and xargs. You can schedule it as a cron command without having to create a script. Also, make sure that you do not disable atime in your ZFS Options.

So I've been using this for a while with no issues but it leaves empty folders. All the files are gone but folders remain. Any ideas?
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,525
That's why I use my script. :) His doesn't do empty directories.
 

Wolfeman0101

Patron
Joined
Jun 14, 2012
Messages
428
I know.. I think I created the thread. But it won't open now since we've upgraded the forum software (thank you ix!). Anyway, here's my code. Use at your own risk or reward:

#!/bin/sh
find /mnt/ -name ".recycle" > /tmp/list
cat /tmp/list | xargs -I % find %/ -atime +3 -exec rm -rf '{}' \;

That finds every folder named .recycle in your /mnt (basically all zpools and UFS mounted locations). It then searches for anything more than 3 days old and deletes it forever.
So where exactly do you store the .sh? I have 1 volume name Vol1 and I stuck the autorecycle.sh in /mnt/Vol1/ and chmod -x and tried to run it and it seems like nothing is happening.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,525
if you have no recycle bin and nothing to delete, then nothing happens! LOL
 
Status
Not open for further replies.
Top