DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2008-08-25 18:41:17

blizzard182
Member
Registered: 2007-09-20
Posts: 52

Deleting Folders older than X

Hi Guys!

I am currently using raid123's Time Machine (http://dns323.kood.org/forum/viewtopic. … 25&p=1) which works great.

Since we back up our mail every day, the database change each day, so we have a lot of space growing.

My goal is to make a script to delete every folder which is older than X days so this is easier.

I found that this might work:

find /path/to/dirs -mtime +2 -type d -depth -exec rmdir -rf {} \

However, this shows me the folders inside the backup (First I am running the command without the -exec rmdir) which are pointing to the older backup, but in the new folder.

Example:

20080822_ABC -> It shows this which is correct
20080825_ABC -> Also shows this, which is not correct but it does it because it finds that inside the folder there are other ones, older than 2 days. I assume this is for the hard-linking.

I found that the current version of find allows the flag -maxdepth which might help, but the DNS-323 doesn't have it.


So, does anyone know a workaround? Or maybe how to upgrade the find bin in the 323?

Thanks!

Offline

 

#2 2008-08-25 19:57:07

blizzard182
Member
Registered: 2007-09-20
Posts: 52

Re: Deleting Folders older than X

Found it!

Here it's a little script to delete the folders older than X days (Replace the 15 with the amount of days that you want)

I made the script first to make a txt file of the folder just to be sure it searches all the disk before attempting to delete the folders.

Note: Only works for raid123's Time Machine. You might need to edit it to use it in another environment.
Note2: TEST IT before you use it.

------------------------------------------------------------------------

#!/bin/sh

find /mnt/HD_b2/ -mtime +15 -type d -name '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][_][0-9][0-9][0-9][0-9][0-9][0-9]' > toDelete.txt

while read EachLine
do
   echo $EachLine
#  Remove the '#' before the next line to actually remove the directory. Now it just showing the folder to check it
#   rm -rf $EachLine 
done < toDelete.txt

rm -f toDelete.txt

-------------------------------------------------------------

I am about to further test this.

Last edited by blizzard182 (2008-08-25 19:58:41)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB