Solved

Automatically delete files based on last accessed time

Posted on 2011-03-01
5
838 Views
Last Modified: 2012-05-11
I'm looking for a way to automatically delete files from our SAN based on last accessed time. SAN vendor doesn't have a method to do this but suggested a program called Delete Files by Date Software. I attempted to test this software but they don't offer any trial period, you can download and view files but in order to test it's functionality you must purchase a license, so while I was uninstalling that waste of time I decided to ask the experts.
I had also tried a program called Delenda, which seems to do what I want but doesn't seem to work. I pointed it at a directory (12k files, 3.5GB) and let it run for 24 hours with no progress.
So what I need is a decent program that can run automatically (as a service preferably) that can delete files based on their last accessed time.

Any suggestions?
0
Comment
Question by:js479
  • 2
  • 2
5 Comments
 
LVL 76

Accepted Solution

by:
arnold earned 250 total points
ID: 35011389
To what server is the LUN allocated?
There is a fairly simple perl script that can run through using stat("$filename")[8] will have the atime for the file. Note that if you mount the LUN with noatime option, the atime will not be current/valid.

It will make matters simpler if there is a specific location where you want to check for files.

A similar mechanism can be setup with a Vbscript/C# using fileobject.
You did not specify the platform your server is on and the use of service suggests a windows based platform.
Out of caution, you migh want to consider an intermediary storage location. I.e. move the files to another directory and then after another period of time delete those files from the other directory.

Might Scheduled task also be an option?
0
 
LVL 5

Assisted Solution

by:group0
group0 earned 250 total points
ID: 35015291
If you're running a *nix-based OS and are trying to recursively delete all files from a starting directory that haven't been accessed in at least n days, this can be easily done with find (the syntax varies between the different flavors):

To see the list of affected files (to verify the affected file list is correct)

find /path-to-start-in -atime +n


To delete the affected files:

find /path-to-start-in -atime +n -exec rm -f {} \;


The {} signifies the filename found, so the exec command can easily be changed to just move the file to a temporary location as suggested earlier:

find /path-to-start-in -atime +n -exec mv -f {} /tmp \;


This may work even on a Windows platform, if you have cygwin or its equivalent installed
0
 
LVL 5

Expert Comment

by:group0
ID: 35015305
As I said, the syntax varies between the different platforms, the examples I provided above are for Linux under CentOS.  Make sure to consult the man pages to be sure if you use this.
0
 
LVL 1

Author Comment

by:js479
ID: 35017503
My apologies for not being more specific in the original question.

The SAN is creating CIFS shares that we can connect to via our windows machines. So the SAN is called DC-BA-01 and I create a CIFS share called Work, I can then access and map that CIFS share from any of my windows servers using \\DC-BA-01\work. All of our servers are either windows 2003 or 2008.


0
 
LVL 76

Expert Comment

by:arnold
ID: 35019896
The san is then running a linux based os with samba shares.
Do you have an option to run jobs on the SAN?
If you are a windows shop, you would use vbscript and fileobject to traverse the directoreis looking at each files atime.

There are many examples of using VBscript to list files in directories, etc. that you can use and incorporate into a script that you need to run as a scheduled task to delete these files.
A simple search for "vbscript list files in directory" will provide several examples.
Using the vbscript guide for fileobject access will provide info on how to use it to access the access time, modify time, create time of the file and then compare and perform action on the file as you see fit.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
The viewer will learn how to set up a document for the web and print and the recommended PPI for printing.
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now