Home » RDBMS Server » Backup & Recovery » script to delete old archivelogs for windows
script to delete old archivelogs for windows [message #145918] Mon, 07 November 2005 12:41 Go to next message
eric777
Messages: 5
Registered: October 2005
Junior Member
Does anyone know of a reliable script I can run via the windows 2003 scheduler which will delete archived log files older than x days ?


I know of a script but it requires Pearl installed.

There may be some out there if I search - but would prefer one that has been tried and tested in the real world.



Re: script to delete old archivelogs for windows [message #146009 is a reply to message #145918] Tue, 08 November 2005 02:55 Go to previous messageGo to next message
girish.rohini
Messages: 744
Registered: April 2005
Location: Delhi (India)
Senior Member
test.vbs
For deleting files older then 3 days
Place this file in same folder in which you want to carry out deletion

Quote:

Dim filesys, demofolder, subfol,fl, folcoll, folist

Dim Path

Set filesys = CreateObject("Scripting.FileSystemObject")

Path=fileSys.GetAbsolutePathName("./")

Set demofolder = filesys.GetFolder(Path)


Set fileCol=demofolder.Files

For Each fl in fileCol

if DateDiff("d",fl.DateCreated,now) > 3 then

if fl.Name="test.vbs" then

'dont do anything

else

fileSys.DeleteFile(Path &"\" & fl.Name)

end if

end if

Next





--Girish
Re: script to delete old archivelogs for windows [message #146020 is a reply to message #146009] Tue, 08 November 2005 04:00 Go to previous messageGo to next message
eric777
Messages: 5
Registered: October 2005
Junior Member
Thank you Girish.
not knowing anything about VB can you answer the following basic questions :-

1. How exactly is the script run
2. Are there any parameters in the script that need adapting for
my environment
3. Can I adapt it to run from another directory - if so how.

Thanks again
Eric

Re: script to delete old archivelogs for windows [message #146107 is a reply to message #146020] Tue, 08 November 2005 13:04 Go to previous message
eric777
Messages: 5
Registered: October 2005
Junior Member
I have created a directory for testing this with some files older than 2 days. Not knowing how to run the script
I tried from the command line using cscript test.vbs but it didn't work - see output below ...
help please as I need this quickly.

ps my pc has windows XP but it will run on a Windows 2003 server - not sure if any adjustments are required ?

Thanks

Directory of C:\test

08/11/2005 17:46 <DIR> .
08/11/2005 17:46 <DIR> ..
08/11/2005 17:47 29 test.bat
08/11/2005 17:47 40 test.log
08/11/2005 17:37 451 test.vbs
08/11/2005 17:44 92 test1.bat
08/11/2005 10:20 19 TEST1.txt
04/11/2005 10:21 11 TEST2.txt
04/11/2005 10:23 11 TEST3.txt
04/11/2005 10:24 20 TEST4.txt
8 File(s) 673 bytes


C:\test>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.


C:\test>dir
Volume in drive C has no label.
Volume Serial Number is 1CB5-8C09

Directory of C:\test

08/11/2005 17:46 <DIR> .
08/11/2005 17:46 <DIR> ..
08/11/2005 17:47 29 test.bat
08/11/2005 17:47 40 test.log
08/11/2005 17:37 451 test.vbs
08/11/2005 17:44 92 test1.bat
08/11/2005 10:20 19 TEST1.txt
04/11/2005 10:21 11 TEST2.txt
04/11/2005 10:23 11 TEST3.txt
04/11/2005 10:24 20 TEST4.txt
8 File(s) 673 bytes




Test.vbs

Dim filesys, demofolder, subfol,fl, folcoll, folist

Dim Path

Set filesys = CreateObject("Scripting.FileSystemObject")

Path=fileSys.GetAbsolutePathName("./")

Set demofolder = filesys.GetFolder(Path)


Set fileCol=demofolder.Files

For Each fl in fileCol

if DateDiff("d",fl.DateCreated,now) > 2 then

if fl.Name="test.vbs" then

'dont do anything

else

fileSys.DeleteFile(Path &"\" & fl.Name)

end if

end if





Previous Topic: swap utilization 97%
Next Topic: Unable to open the database
Goto Forum:
  


Current Time: Fri Apr 19 12:21:21 CDT 2024