File Server Recycle Bin - how to automatically delete files older than X days

NethServer Version: 7.9.2009
Module: File Server

Hello @support_team,

I’ve installed File Server on my Nethserver for folder sharing. I’ve enabled the Recycle Bin on a folder where nightly older files are automatically deleted. It appears my Recycle Bin folder for this file share has grown very large. I’ve asked this question before but wanted to confirm the answer:

where a shell script can be used:

#!/bin/sh
find /var/lib/nethserver/ibay/ /Recycle -mindepth 1 -atime +30 -print0 | xargs -0r rm -rfv

Would the above script go through all my shared folder recycle bins and delete any files older than 30 days?

Is the preferred method still to use this in a cron job to clean up my recycle bin? Or is there a way now within the Nethserver/Cockpit GUI to setup this task?

Any advice for me on how to reduce the size of my recycle bin?

Thank you.

I use a script like this one and place it in /etc/cron.monthly :

#!/bin/bash

#ensure finds includes hidden files in the Recycle Bins
shopt -s dotglob

echo
echo “±-------------------------------------------------------------------------------------------------------------------------------+”
echo “Samba recycle-bin cleaner”
echo “±-------------------------------------------------------------------------------------------------------------------------------+”

URF=$(find “/var/lib/nethserver/nextcloud/Frederik_POLLET/files/00. MyOwnFiles/01. Tekstbestanden/001. BOEKHOUDING PRO/.Prullenbak/”* -type f -atime +7)
if [ “URF" != "" ] then printf " %-126s \n" "De volgende bestanden uit de prullenbak van Frederik (accdocspro) werden verwijderd :" IFS=’\n’
for file in $URF
do
printf " - %-124s \n” “$file”
rm -f “$file”
done
else
printf " %-126s \n" “Er werden geen oude bestanden uit de prullenbak van Frederik (accdocspro) verwijderd.”
fi

echo “±-------------------------------------------------------------------------------------------------------------------------------+”
echo

URD=$(find “/var/lib/nethserver/nextcloud/Frederik_POLLET/files/00. MyOwnFiles/01. Tekstbestanden/001. BOEKHOUDING PRO/.Prullenbak/”* -type d -empty)
if [ “URD" != "" ] then printf " %-126s \n" "De volgende lege mappen uit de prullenbak van Frederik (accdocspro) werden verwijderd :" IFS=’\n’
for folder in $URD
do
printf " - %-124s \n” “$folder”
rm -rf “$folder”
done
else
printf " %-126s \n" “Er werden geen lege mappen uit de prullenbak van Frederik (accdocspro) verwijderd.”
fi

echo “±-------------------------------------------------------------------------------------------------------------------------------+”
echo

<

1 Like

Thank you Frederik for your reply. But it appears your script handles the recycle bin for Nextcloud. If I’m not mistaken I thought there was a setting in the Nextcloud config to set the retention period for how long to keep files in the recycle bin.

For my case I’m looking to cleanup files in my Shared Folder (in File Server) on my Nethserver. I’ve tried using the following command:

#!/bin/sh
find /var/lib/nethserver/ibay/mysharedfolder/Recycle\ Bin/ -mindepth 1 -atime +10 -print0 | xargs -0r rm -rfv

This appears to be working to cleanup any files in my Recycle bin that are older than 10 days. But when I look at the size of my Shared Folders in Nethserver I don’t see the Size reduced. I’ve confirmed that the recycle bin folder does have less files now. @support_team, is there something more I need to do in order to reclaim the used space my recycle bin had taken up before I ran my cleanup script?

Thank you.

@greavette

Hi

AFAIK, there’s a nightly job on NethServer which calculates the DU…
Just wait until the next day - or set your job before the DU-task…

-> The DU task takes too long to run it every change in the file system…

TIP: run a df before and after the job, you’ll see the difference…

My 2 cents
Andy

2 Likes

Much appreciative of your input @Andy_Wismer! I can see this morning that the size of my shared folder has been now greatly reduced reflecting the cleanup I did yesterday.

I will now install crontab manager to setup a regular task to keep my shared folder recycle folders clean.

Thank you.

Hi,

Indeed, but i can reach my Nextcloud-data via Samba-shares …
You can adapt the script for other shares, ex the Samba-shares made in Cockpit.

F.

1 Like